|
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 |
ironik Smarty n00b
Joined: 27 Feb 2005 Posts: 2
|
Posted: Mon Feb 28, 2005 10:46 pm Post subject: Smarty 'urlify' plugin |
|
|
Not sure if this is the place for it, but I thought this might be useful. I use a urlify function to create links out of plain text matches using this regular expression. I haven't been able to test it fully in smarty yet, but the regex works fine so in theory it should just transfer over. Works well in community building where users don't need bb code or knowledge of html <a> links to create hyperlinks.
Hoping someone has a chance to test it in smarty... see how it goes?
Code: |
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* @file modifier.urlify.php
* Smarty 'urlify' modifier plugin
*
* Type: modifier<br>
* Name: urlify<br>
* Purpose: turn url text into hyperlinks
* Example: {$var|urlify}
* @param string
* @return string
*/
function smarty_modifier_urlify($string)
{
$pattern ="{\\b((https?|telnet|gopher|file|wais|ftp) : [\\w/\\#~:.?+=&%@!\\-]+?) (?= [.:?\\-]* (?:[^\\w/\\#~:.?+=&%@!\\-] |$) ) }x";
return preg_replace ($pattern, "<a href=\"$1\" target=\"" . $target . "\">$1</a>", $string);
}
?>
|
Last edited by ironik on Mon Feb 28, 2005 11:00 pm; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Feb 28, 2005 10:55 pm Post subject: |
|
|
I think you want $string and not $html (just looking at it) |
|
Back to top |
|
ironik Smarty n00b
Joined: 27 Feb 2005 Posts: 2
|
Posted: Mon Feb 28, 2005 11:01 pm Post subject: |
|
|
d'oh! thats what I get for not testing first . My orginal function used a $html var. |
|
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
|