php_begins Posted November 28, 2011 Share Posted November 28, 2011 I retrieve urls that have the following path $url=http://cdn.test1.com $url=http://cdn.test2.com and so on... i want to to do a string replace such that it displays http://test.com,http://test2.com and son without the cdn part. Will the following work for all cases? $url=str_replace("cdn.","",$url); Link to comment https://forums.phpfreaks.com/topic/251982-replace-cdn/ Share on other sites More sharing options...
requinix Posted November 28, 2011 Share Posted November 28, 2011 Yes. And probably for cases that you don't want it to. Link to comment https://forums.phpfreaks.com/topic/251982-replace-cdn/#findComment-1291957 Share on other sites More sharing options...
php_begins Posted November 28, 2011 Author Share Posted November 28, 2011 thanks..wat if i want to replace the cdns only at the start of the url? Link to comment https://forums.phpfreaks.com/topic/251982-replace-cdn/#findComment-1291959 Share on other sites More sharing options...
requinix Posted November 28, 2011 Share Posted November 28, 2011 You could search for http://cdn.... Link to comment https://forums.phpfreaks.com/topic/251982-replace-cdn/#findComment-1291968 Share on other sites More sharing options...
php_begins Posted November 28, 2011 Author Share Posted November 28, 2011 I tried something like this but didnt seem to wrk. $url=preg_replace( 'http://cdn.','http://',$url); Link to comment https://forums.phpfreaks.com/topic/251982-replace-cdn/#findComment-1291979 Share on other sites More sharing options...
requinix Posted November 28, 2011 Share Posted November 28, 2011 Don't use preg_replace() unless you have a regular expression. Which you don't. Go back to str_replace(). Link to comment https://forums.phpfreaks.com/topic/251982-replace-cdn/#findComment-1291984 Share on other sites More sharing options...
php_begins Posted November 28, 2011 Author Share Posted November 28, 2011 i feel stupid now..all i need to do was this.. $url=str_replace("http://cdn.","http://",$url); Link to comment https://forums.phpfreaks.com/topic/251982-replace-cdn/#findComment-1291986 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.