chriso20 Posted February 16, 2009 Share Posted February 16, 2009 Hey, Quick question - How can i preg_replace (or whatever i need) these strings: <a href="http://www.google.com"> <a href='www.anothersite.co.uk'> <a href=whatever.net> so they're replaced with: <a href="mysite.com?url=http://www.google.com"> <a href="mysite.com?url=http://www.anothersite.co.uk"> <a href="mysite.com?url=http://www.whatever.net"> Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/145484-regular-expressions-amending-urls/ Share on other sites More sharing options...
premiso Posted February 17, 2009 Share Posted February 17, 2009 As long as they are always <a href= a simple str_replace will work: $string = '<a href="http://www.site.com">Site.com</a>'; $string = str_replace('<a href="', '<a href="http://www.mysite.com/?url=', $string); echo $string; Quote Link to comment https://forums.phpfreaks.com/topic/145484-regular-expressions-amending-urls/#findComment-763832 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.