miob Posted September 25, 2007 Share Posted September 25, 2007 hello ! here is what i have $threadx = preg_replace("/((ht|f)tp:\/\/[^\s&]+)/", "<a href=\"$1\">$1</a>", $threadx); $threadx = preg_replace("/(\\S+@\\S+\\.\\w+)/", "<a href=\"mailto:$1\">$1</a>", $threadx); can someone tell me how to make it better, this one completly screws up existing hyperlinks and <img src=""> tags... need to fix it somehow... thanx Link to comment https://forums.phpfreaks.com/topic/70670-url-text-to-hyperlink/ Share on other sites More sharing options...
chocopi Posted September 25, 2007 Share Posted September 25, 2007 try something like this: <?php $string = // some rubbish $pattern[0] = "%(http|https|ftp)(://.*?)%"; $pattern[1] = "%((http|https|ftp)(://.*?)(jpg|bmp|gif|jpeg|png))%"; $replacement[0] = "<a href=\"\$1\$2\">\$1\$2</a>"; $replacement[1] = "<img src=\"\$1\" />"; for($i = 0; $i <= 1; $i++) { $string = preg_replace($pattern[$i],$replacement[$i],$string); } ?> ~ Chocopi Link to comment https://forums.phpfreaks.com/topic/70670-url-text-to-hyperlink/#findComment-355244 Share on other sites More sharing options...
miob Posted September 25, 2007 Author Share Posted September 25, 2007 tried it, but also screwed it again i have in text this: <img src=http://www.autobazar.eu/images/smiles/6.gif border=0> i think that's due to char " and from full URL path in text got hyperlink only http:// Link to comment https://forums.phpfreaks.com/topic/70670-url-text-to-hyperlink/#findComment-355315 Share on other sites More sharing options...
chocopi Posted September 27, 2007 Share Posted September 27, 2007 try using mysql_real_escape_string $string = mysql_real_escape_string($string); That should fix it, I hope ~ Chocopi Link to comment https://forums.phpfreaks.com/topic/70670-url-text-to-hyperlink/#findComment-356571 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.