Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

New Smarty function: substring (code included)

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
jotango
Smarty Rookie


Joined: 20 Apr 2005
Posts: 13

PostPosted: Wed Dec 13, 2006 12:41 pm    Post subject: New Smarty function: substring (code included) Reply with quote

Hello,

we needed substr in our application, so we built a 1:1 wrapper for the PHP substr function. Perhaps its useful for someone else.

Best regards

Jan


Code:
<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 * @author Manuel Polacek / Hitflip
 */


/**
 * Smarty regex_replace modifier plugin
 *
 * Type:     modifier<br>
 * Name:     substring
 * Purpose:  substring like in php
 * @param string
 * @return string
 */
function smarty_modifier_substring($sString, $dFirst = 0, $dLast = 0) {
    if($dLast == 0) {
       return substr($sString, $dFirst);
    } else {
       return substr($sString, $dFirst, $dLast);
    }
}

?>
[/code]
Back to top
View user's profile Send private message
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Wed Dec 13, 2006 2:02 pm    Post subject: Reply with quote

You can also just use PHP's substr as a modifier, without making a custom plugin.

Code:

{$mystring|substr:5:10}
{$mystring|substr:5}

_________________
Smarty site with one index.php controller file
Working with MySQL and Smarty
SmartyColumnSort
Custom Smarty Javascript Debug Template
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP