AzaraT Posted July 15, 2010 Share Posted July 15, 2010 Hi,What I want to do is to take a link like this http://test.com and make it into http.//www.mydomain.com/redirect.php?site=test.comI got my data in a string (they need to be submitted to a database). So I've tried using str_replace like this: $content2 = str_replace("http://", "http.//www.mydomain.com/redirect.php?mid={$msg_id}&site=", $content); however what I get from this is a link to http://localhost:8888/%22http://www.mydomain.com/redirect.php?site=test.com\%22 Which I really dont get (note I'm currently testing on my localhost..)Someone can help me get this done correctly? Thanks a lotJacob / AzaraT Link to comment Share on other sites More sharing options...
justsomeguy Posted July 15, 2010 Share Posted July 15, 2010 Have you printed $content to see what it is? It looks like str_replace is either not running, not finding the text to replace, or you're doing something else with $content2. The reason I say that is because str_replace tells it to add a querystring variable called mid, but that doesn't show up in what you printed. Link to comment Share on other sites More sharing options...
ApocalypeX Posted July 19, 2010 Share Posted July 19, 2010 Here is your problem$content2 = str_replace("http://", "http.//www.mydomain.com/redirect.php?mid={$msg_id}&site=", $contentYou put a period instead of a colon. Link to comment Share on other sites More sharing options...
AzaraT Posted July 19, 2010 Author Share Posted July 19, 2010 For some reason I didn't get a notification email before today about the replys.Meanwhile I found a solution: function callback($match) { global $msg_id;return "http://www.mydomain.com/redirect.php?mid=" . $msg_id . "&&site=" . parse_url($match[1], PHP_URL_HOST);}$content = '<a href="http://test.com">test</a> <p> Other html code here blablabla </p>';//this is where the changes take effect...$content = preg_replace_callback('~(http://[^ "]+)~i', 'callback', $content); Thanks anyway Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.