Hi everyone, couldn't find the answer from searching. PHP & MySQL: How can I recognize a url, and turn it into a HTML hyperlinked url. without, having like [url]http://www.example.com I got the above to work, but can I get it to recongize without the [url]and have it convert the url to a hyperlinked url? Thanks for the help, I appreciate you guys help all the time, thank you! Warmly, Wesley
|
Try something like this.
$pattern = "/http:\/\/(www\.)?([^.]+\.[^.\s]+\.?[^.\s]*)/i"; $replace = "<a href='http://\\1\\2'>http://\\1\\2</a>"; $string = preg_replace($pattern,$replace,$string); echo $string;
Where $string is the text. Just a couple notes about this pattern: 1) The URI MUST have "http://" before it 2) It works for URIs formatted in the following ways >>>http://www.example.foo >>>http://www.example.foo.foo #having two >>>http://example.foo >>>http://example.foo.foo #having two >>>http://foo.exmaple.foo #pretty much the same as above I know this is missing a possibility but I figured I'd get you on the right track ;) Good luck!
|