I trying to write a little something in PHP, and seem to have done alright thus far, but have gotten a little stuck. All it has to do is detect when there is a hyperlink in a string, and replace the link with the relevant markup. e.g. replace
withCode:Just visit http://www.example.com to find out more
The best I can come up with is something like this:Code:Just visit <a href="http://www.example.com">http://www.example.com</a> to find out more
Where $string is a string of all of the valid characters for a URL. So, the questions are:Code:$text = preg_replace("/http:\/\/([$string]+)/",'<a href="http://$1">http://$1</a>',$text);
1) What are the valid characters for a URL i.e. what should $string be?
2) Is there a better way of doing this?
3) Are there any examples of this on the net?
I did try searching for this, but all I could find was a irrelevant PHP function.
Any help is appreciated.
Mike.


LinkBack URL
About LinkBacks
Reply With Quote



