|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
spib Smarty Rookie
Joined: 06 Jul 2003 Posts: 7
|
Posted: Sat Jul 26, 2003 6:53 am Post subject: modifier to parse urls |
|
|
Hey guys,
Is there a modifier which will parse a text block and convert any urls into hyperlinks?
For example:
Code: | This is a great web site - http://smarty.php.net |
would be converted to
Code: | This is a great web site - <a href="http://smarty.php.net">http://smarty.php.net</a> |
|
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Sat Jul 26, 2003 1:48 pm Post subject: |
|
|
I didn't see one on the plugins page so I wrote one up real quick using some code I had from past projects.[php:1:f906251861]<?php
/**
* Transforms text hyperlinks into html anchors (<a href="...">...</a>))
* Slightly modified from comment on http://www.php.net/manual/en/function.preg-replace.php
* Thanks to jeff.royIAMSURE@HEDOESNTWANTcruisingworld.comSPAM
*/
function smarty_modifier_parse_hyperlinks($string) {
$string = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2", $string);
$string = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i", "<a target=\"_blank\" href=\"$1\">$1</a>", $string);
$string = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i", "<a href=\"mailto:$1\">$1</A>", $string);
return $string;
}
?>[/php:1:f906251861]
EDIT:
but knowing me I wonder arround the site long enough and find this http://marc.theaimsgroup.com/?l=smarty-general&m=104378865428811&w=2 _________________ "Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|