note 47593 added to function.preg-replace
| From: | manithu at fahr-zur-hoelle dot org | Date: | Mon, 22 Nov 2004 13:26:35 +0000 |
| Subject: | note 47593 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80862@lists.php.net to get a copy of this message | ||
This function is better than paul's, it 'stops' linking after a white-space. It also
converts uris without http://(optional).
<?
function convert_links($str, $www = false) {
#this converts http://* the link ends at the next space or(if there is no
space) at the end of the string.
$str = preg_replace('#(http://)([^\s]*)#', '<a
href="\\1\\2">\\1\\2</a>', $str);
#optional, replaces www.*
if($www) {
$str = preg_replace('=(www.)([^\s]*)=', '<a href="http://\\1\\2">\\1\\2</a>', $str);
}
return $str;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47593
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47593&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47593&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47593&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47593&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47593&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47593&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47593&report=yes
Search -- http://master.php.net/manage/user-notes.php