poe Posted October 22, 2011 Share Posted October 22, 2011 i have this string "basePath":"\/" how do i do a preg_replace to this "basePath":"www.mypage.com\/" i tried this, but doesnt work $repWhat = "/\"basePath\":\"\/\"/i"; $toWhat = "\"basePath\":\"www.mypage.com\/\""; $html = preg_replace($repWhat, $toWhat, $html); thanks Link to comment https://forums.phpfreaks.com/topic/249603-arrgh-preg_replace/ Share on other sites More sharing options...
xyph Posted October 22, 2011 Share Posted October 22, 2011 No need for RegEx <?php $str = '"basePath":"\/"'; $toAdd = 'http://mypage.com'; $final = substr($str,0,12) . $toAdd . substr($str,12); echo $final; ?> Link to comment https://forums.phpfreaks.com/topic/249603-arrgh-preg_replace/#findComment-1281416 Share on other sites More sharing options...
poe Posted October 22, 2011 Author Share Posted October 22, 2011 i am reading an html file... i do not have the string.. i am trying to find it... so the string i am looking for is "basePath":"\/" so i need to find the string in the page and change to "basePath":"www.mypage.com\/" ie. here is part of the full string i am searching <!--//--><![CDATA[//><!-- jQuery.extend(Drupal.settings, {"basePath":"\/","pathPrefix":"","ajaxPageState":{"theme":"base","theme_token":"5XoHI1_0PUfE Link to comment https://forums.phpfreaks.com/topic/249603-arrgh-preg_replace/#findComment-1281421 Share on other sites More sharing options...
xyph Posted October 22, 2011 Share Posted October 22, 2011 User strpos to get the offset of "basePath":" Insert that offset into substr Et voila Link to comment https://forums.phpfreaks.com/topic/249603-arrgh-preg_replace/#findComment-1281445 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.