I have the following string:
"Look on http://www.google.com".
I need to convert it to:
"Look on http://www.google.com"
The original string can have more than 1 URL string.
How do I do this in php?
Thanks
I have the following string:
"Look on http://www.google.com".
I need to convert it to:
"Look on http://www.google.com"
The original string can have more than 1 URL string.
How do I do this in php?
Thanks
You can use the following:
PHP versions < 5.3 (ereg_replace) otherwise (preg_replace)
Have a look at regular expressions. You would then do something like:
You will need to use regular expressions...
Something like this will help.
Checkout my linkify function, which uses preg_replace_callback (PHP 5.3 only). It supports http, email and twitter:
http://www.jasny.net/articles/linkify-turning-urls-into-clickable-links-in-php/
I found this code at http://code.seebz.net/p/autolink-php/ and tweaked it a bit to recognize www.* as links. I am not very conversant with regular expressions but I think the two str_replace lines can be modified to one regexp
I found an example which allows for links that include ftp, https and others which seems to work fine for multiple URLs
how-to-detect-urls-in-text-and-convert-to-html-links-php-using-regular-expressions
Proabably a good idea to add nofollow to the link too is it's a user submitted value.