Jump to content

convert url to links


gdfhghjdfghgfhf

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.