08-14-2008, 12:27 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: Apr 2007
Location: Hampshire
Posts: 28
Thanks: 1
|
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;
}
|
|
|