PHPNewbie55 Posted March 31, 2008 Share Posted March 31, 2008 Hello, I am trying to replace certain portions of an url, but for the life of me I can't get it to work correctly... Frankly.. I am embarassed to show you what I have TRIED.... because nothing has worked. So here is what I am trying to do... I have some urls in my database that are something like this. http://www.XblahXblah.com/someplace/else/id/551478/track.php?&url=http://www.XanotherXblahXblah.com Now what I can't figure out is the pattern to replace everything before the &url= to just have the regular link... I have tried preg_replace but I can't seem to get the pattern right to replace what I want... Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/98772-help-with-replacement/ Share on other sites More sharing options...
sasa Posted March 31, 2008 Share Posted March 31, 2008 <?php $a = 'http://www.XblahXblah.com/someplace/else/id/551478/track.php?&url=http://www.XanotherXblahXblah.com'; preg_match('/url=([^&]+)/' ,$a, $b); echo $b[1]; ?> Link to comment https://forums.phpfreaks.com/topic/98772-help-with-replacement/#findComment-505435 Share on other sites More sharing options...
PHPNewbie55 Posted March 31, 2008 Author Share Posted March 31, 2008 Perfect... Thank You!!! Link to comment https://forums.phpfreaks.com/topic/98772-help-with-replacement/#findComment-505444 Share on other sites More sharing options...
GingerRobot Posted March 31, 2008 Share Posted March 31, 2008 Or: <?php $a = 'http://www.XblahXblah.com/someplace/else/id/551478/track.php?&url=http://www.XanotherXblahXblah.com'; list($url,$junk) = explode('?',$url,2); ?> Avoids the overhead of the regex. Link to comment https://forums.phpfreaks.com/topic/98772-help-with-replacement/#findComment-505445 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.