RE: [SMARTY] selecting 4 characters starting from right of string

From: Date: Thu, 17 Feb 2005 15:55:55 +0000
Subject: RE: [SMARTY] selecting 4 characters starting from right of string
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12249@lists.php.net to get a copy of this message
If you might ever need to check multiple file formats, what I would do is make my own plugin that uses preg_match - this way you avoid ugly pseudo php inside a smarty tag in your TPL. e.g. if you make the checkformat plugin something like this: // untested code below beware function smarty_function_checkformat($params, &$smarty){ if($params['filename'] && $params['format']){ if(preg_match("/". $params['format']."$/", $params['filename'])==1){ // good }else{ // bad $smarty->trigger_error("Invalid Format"); } } } Then in your template you can do {checkformat filename="$fileToTest" format=".jpg"} A lot more reusable and easier to read. * * * Geoff

« previous php.smarty.general (#12249) next »