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 Quote Link to comment 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; ?> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.