Click to See Complete Forum and Search --> : search for all links in a text and translating them to HTML


SZero
04-24-2008, 01:15 AM
hi every1
i have a little question, i have this large text, i wanna use php to convert any sentence starting with http:// till a space is found to a hyperlink in html, can it be done?
ty..

SZero
04-28-2008, 03:27 AM
any1??

the-ferret
04-28-2008, 05:26 AM
Have you tried preg_match (google it for more info)

andre4s_y
04-28-2008, 06:38 AM
<?php
$pattern = "#http:\/\/.+\b#Ui";
$source = "Your large text here";
preg_match_all($pattern,$source,$match);
//$match[0][0] first match
//$match[0][1] second match.. and so on..
#if you want your matches to be replace with <a>tag, use this
$replacement = "<a href=\"$0\">$0</a>";
$tag_match = preg_replace($pattern,$replacement,$match[0]);
//$tag_match[0] = <a href="http://...first">http://...first</a>
//$tag_match[1] = <a href="http://...second">http://...second</a>
?>