darkfreaks Posted February 19, 2008 Share Posted February 19, 2008 can anyone tell me how to modify the following statement so its an ereg_replace and not preg for some reason it will not work in my function if it is not ereg_replace ??? <?php $text = preg_replace("/[^a-z]+[^:\/\/](www\.". "[^\.]+[\w][\.|\/][a-zA-Z0-9\/\*\-\?\&\%\=\,\.]+)/", " <a href=http://\\3>\\3</a>", $text);?> Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted February 19, 2008 Share Posted February 19, 2008 Well, your missing the / delimiter at the end of your regex. Perhaps that is why your preg_replace isn't working? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted February 19, 2008 Author Share Posted February 19, 2008 which line ??? Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted February 19, 2008 Share Posted February 19, 2008 the last line, right after </a> and before the " Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted February 19, 2008 Author Share Posted February 19, 2008 what i really need is a regex expression that matches the following format for ereg_replace http://www.mysite.com/index.php?action=whatever www.mysite.com http://www.mysite.com Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted February 19, 2008 Share Posted February 19, 2008 Take a look at this: http://www.php.net/manual/en/function.eregi-replace.php#79451 It may be exactly what you need Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted February 19, 2008 Share Posted February 19, 2008 OK, I fooled around with it and got it working: <?php $str = "Please go visit http://www.mysite.com/index.php?action=whatever"; $str .= " Please go visit http://www.mysite.com"; $str .= " Please go visit www.mysite.com"; function transformUrl($str){ $str=utf8_decode(urldecode($str)); $str=eregi_replace("(^| |>)(www([.]?[a-zA-Z0-9_/-?])[^< ]*)", "\\1<a href=\"http://\\2\">\\2</a>", $str); $str=eregi_replace("(^| |>)(http://www([.]?[a-zA-Z0-9_/-?])[^< ]*)", "\\1<a href=\"\\2\">\\2</a>", $str); $str=eregi_replace("(^| |>)(http://([.]?[a-zA-Z0-9_/-?])[^< ]*)", "\\1<a href=\"\\2\">\\2</a>", $str); return utf8_encode($str); } echo transformUrl($str); ?> 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.