View Single Post
Old 08-14-2008, 12:27 PM   #1 (permalink)
localhost
The Contributor
 
localhost's Avatar
 
Join Date: Apr 2007
Location: Hampshire
Posts: 28
Thanks: 1
localhost is on a distinguished road
Default Parsing URL in text

Hello,

I have paragraphs of text in a database, and I am trying to convert the url's to proper links, e.g. :
This site Google is cool
would be : This site Google is cool

and the same if they had http:// on.

So far my code isn't working, so please I would be grateful if someone could help me achieve above.

Many Thanks,

Steven Gibbons

PHP Code:
if(!empty($data)) {
$url mysql_real_escape_string($_POST['url']);
$text preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@''<a href="$1">$1</a>'$url);
echo 
$text;

__________________
Send a message via MSN to localhost Send a message via Skype™ to localhost
localhost is offline  
Reply With Quote