Forum Moderators: coopster

Message Too Old, No Replies

How can I automatically parse URLs?

         

imagined

10:00 pm on Apr 1, 2004 (gmt 0)

10+ Year Member



ok. Let's say I have this page and the content is stored in a MySQL database. So the text that I want to displayed is placed in $message variable. Before echoing this variable I want to automatically parse the URLs. Note that $message is not the link is like a whole paragraph and there are links in it.

Let's say that the text includes this:

www.devshed.com
[devshed.com...]
[devshed.com...]

How could I have a script to see this and add the <a hre f> tags to it?

i tried this, but i dont know why it doesnt work.

$message = preg_replace( "/www.+/i", "[<a href=\"\0\" target=\"_blank\">www</a>]", $message );

andylarks

12:55 pm on Apr 2, 2004 (gmt 0)

10+ Year Member



Dunno if this will do what you want, but you could try this:

$message = explode("\r\n",$message);
for ($x=0;$x<sizeof($message);$x++) {
$url = '<a href="'.$message[$x].'">description</a>
}

Hope that helps :)

Andy