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);?> Link to comment https://forums.phpfreaks.com/topic/91828-changing-preg_replace/ 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? Link to comment https://forums.phpfreaks.com/topic/91828-changing-preg_replace/#findComment-470294 Share on other sites More sharing options...
darkfreaks Posted February 19, 2008 Author Share Posted February 19, 2008 which line ??? Link to comment https://forums.phpfreaks.com/topic/91828-changing-preg_replace/#findComment-470295 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 " Link to comment https://forums.phpfreaks.com/topic/91828-changing-preg_replace/#findComment-470296 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 Link to comment https://forums.phpfreaks.com/topic/91828-changing-preg_replace/#findComment-470299 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 Link to comment https://forums.phpfreaks.com/topic/91828-changing-preg_replace/#findComment-470305 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); ?> Link to comment https://forums.phpfreaks.com/topic/91828-changing-preg_replace/#findComment-470313 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.