note 72787 deleted from function.preg-replace by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 20:08:18 +0000 |
| Subject: | note 72787 deleted from function.preg-replace by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127718@lists.php.net to get a copy of this message | ||
Note Submitter: Allen Panclape
----
I don't know about you, but I like to keep my scripts short, but effective. Here is a very
short function used to parse URLs into links.
<?php
$text="I like http://www.yahoo.com, http://www.google.com,
and I connect through FTP to my site through ftp://www.mysite.com.";
function url_links($string)
{
$string=preg_replace("/(http:\/\/|ftp:\/\/)([^\s,]*)/i","<a
href='$1$2'>$1$2</a>",$string);
return $string;
}
print url_links($text);
?>