Smarty variable modifier that adds links to :// www. and @ in the string
| From: | Zoran Knezevic | Date: | Wed, 17 Sep 2003 09:40:51 +0000 |
| Subject: | Smarty variable modifier that adds links to :// www. and @ in the string | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-10229@lists.php.net to get a copy of this message | ||
Hi ALL!
all "guestook-like" scripts where people can leave their
coments are much more usable if links like
http://smarty.php.net are clickable. The same thing is with
mailto. I wrote this modifier and I hope it will be useful
to somebody.
Have good time. See you arround.
I have allready post this script at smarty forum:
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1068
<?php
/*
* Smarty plugin
* -----------------------------------------------------------
--
* Type: modifier
* File name: modifier.makelinks.php
* Name: makelinks
* Purpose: Authomaticaly add links to strings that starts
with
* " www." or contains "://" and "@" if the
string
* contains email address
*
* Install: Just drop into the plugin directory.
*
* Autor: Zoran Knezhevich (elenaizoka[at]lsinter.net)
*
* Suggestions for further developemant:
* Add a new parameter and limit the length of the
text
* bitween <a> and </a> because sometimes long urls
* strech the table
* -----------------------------------------------------------
--
*/
function smarty_modifier_makelinks($string,
$target="_blank")
{
# part for ftp:// http:// and similar *:// links
$ret = eregi_replace( "([[:alnum:]]+)://([^[:space:]]*)
([[:alnum:]#?/&=])", "<a href=\"\\1://\\2\\3\"
target=\"$target\">\\1://\\2\\3</a>", $string);
# part for strings that start fith " www." I know it is
dirty but do the job
$ret = eregi_replace("^www."," www.",$ret);
$ret = eregi_replace( "([[:space:]]|\a+)www.([^[:space:]]
*)([[:alnum:]#?/&=])", "\\1<a href=\"http://www.\\2\\3\"
target=\"$target\">www.\\2\\3</a>", $ret);
#part for email linking
$ret = eregi_replace( "(([a-z0-9_]|\\-|\\.)+@([^
[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\\1\"
target=\"_new\">\\1</a>", $ret);
return($ret);
}
?>