Guest Posted June 26, 2010 Share Posted June 26, 2010 i'm trying to convert all URL to links i'm currently using this code: <?php $str = "http://www.i-want-to-convert-this.com <br> <a href=\"http://www.this-link-is-already-converted.com/i-dont-want-to-convert-it.html\">Don't convert this !</a>"; $str = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\" rel=\"nofollow\">\\0</a>", $str); echo $str; ?> but this code is also converting URL that are already linked with the <a href> tag can someone help me to modify this code to convert only URL without the <a href> tag ?? thanks a lot! Link to comment https://forums.phpfreaks.com/topic/205963-convert-url-to-links/ Share on other sites More sharing options...
monkeytooth Posted June 27, 2010 Share Posted June 27, 2010 I'm not entirely that great with regex. But I think if you build a regex statement to find the structure of a url be it ftp, irc, mailto, http, https.. and the like.. or multiple regex types to run through for each specific type of structure. Then if found take that bit of the string and wrap a link tag around it. Its just a random thought off my head but im thinking regex is more likely your best route to go. Link to comment https://forums.phpfreaks.com/topic/205963-convert-url-to-links/#findComment-1077732 Share on other sites More sharing options...
Guest Posted June 27, 2010 Share Posted June 27, 2010 i already have a code to do that... problem is that it will also convert existing links Link to comment https://forums.phpfreaks.com/topic/205963-convert-url-to-links/#findComment-1077919 Share on other sites More sharing options...
Guest Posted July 1, 2010 Share Posted July 1, 2010 bump Link to comment https://forums.phpfreaks.com/topic/205963-convert-url-to-links/#findComment-1079424 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.