I found this at http://www.phpinsider.com/smarty-forum/ ... hp?t=10384
posted by JasonDS and used joeri210's version (code below)
saved file as: lib/smarty/plugins/modifier.contains.php
Code: Select all
<?php
/**
* Smarty shared plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Function: smarty_contains
* Purpose: Used to find a string in a string
* Example: contains( 'Jason was here', 'here' ) returns true
* Example2: contains( 'Jason was here', 'ason' ) returns false
* Usage string: {$foo|contains:"bar"}
* Usage array: {$foo|@contains:"bar"}
* @author Jason Strese <Jason dot Strese at gmail dot com>
* @param string
* @return string
*/
function smarty_modifier_contains($string, $find, $cases = false)
{
$count = 0;
if( is_string($string) && !empty($string) )
{
if($cases) $count = substr_count($string, $find);
else $count = substr_count(strtolower($string), strtolower($find) );
}
elseif( is_array($string) && count($string) )
{
if($cases)
{
foreach($string as $str) {
if($str == $find) $count++;
}
} else {
foreach($string as $str) {
if(strtolower($str) == strtolower($find)) $count++;
}
}
}
return $count;
}
/* vim: set expandtab: */
?>
Alane