Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php have an "auto link" function?

Status
Not open for further replies.

unborn

Programmer
Joined
Jun 26, 2002
Messages
362
Location
US
basically for my news script i was wondering if there was some kind of function where if it reads a http:// or www. it will then output it as a html link. figured php seems to have everything else might as well ask about this :D

and if not maybe you could throw some hints to me about hot to go about doing it myself? thanks!

in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
I use this one:

<?
function addLink($link) {
$link = str_replace(&quot; //removes http:// if present.....
$link = preg_replace(&quot;/(?:^|\b)(((www\.))([\w\.]+)([,:%#&\/?=\w+\.-]+))(?:\b|$)/is&quot;, &quot;<a href=\&quot; target=\&quot;_blank\&quot;>$1</a>&quot;, $link);

return $link;
}

$myLink=&quot;// or $myLink=&quot;// works fine also....
print addLink($myLink);
?>

H.T.H.

Quasibobo

Don't eat yellow snow!
 
KempCGDR :
i totally agree with u. RegExp will be my downfall... :(

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top