blokey
asked on
Detect a link
How can I detect a link in a string and surround that link with the <a href> tag?
For example:
$str = "visit my site at http://www.something.com or http://www.somethingelse.com";
I would then want that to become
$str = "visit my site at <a href=\"http://www.something.com\">http://www.something.com</a> or <a href=\"http://www.somethingelse.com\">http://www.somethingelse.com</a>";
Im thinking of using regular expressions, but I dont know how to go about it.
Blokey
For example:
$str = "visit my site at http://www.something.com or http://www.somethingelse.com";
I would then want that to become
$str = "visit my site at <a href=\"http://www.something.com\">http://www.something.com</a> or <a href=\"http://www.somethingelse.com\">http://www.somethingelse.com</a>";
Im thinking of using regular expressions, but I dont know how to go about it.
Blokey
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The accepted answer only creates a link for the domain name not the entire URL, How can we fix that?
print $str;