Re: how to do a ireplace
| From: | Monte Ohrt | Date: | Thu, 08 Feb 2001 17:06:00 +0000 |
| Subject: | Re: how to do a ireplace | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-96@lists.php.net to get a copy of this message | ||
Beware if you send a blank $search, preg_replace will put the $replace
string between every character of $string. Maybe as a safety catch, exit
the function if $search is empty. Also keep in mind, if a template
designer tries to use ireplace with missing parameters, they will see
PHP errors. That is the current behavior of replace too.
function smarty_mod_ireplace($string, $search, $replace)
{
if(empty($search))
return $string;
return preg_replace("/".preg_quote($search)."/i", $replace,
$string);
}
Joris Trooster / Interstroom wrote:
>
> HOWTO ireplace:
>
> For case INsensitive replace add the folowing at the end of
> Smarty.addons.php
>
> function smarty_mod_ireplace($string, $search, $replace)
> {
> return preg_replace("/".preg_quote($search)."/i", $replace,
> $string);
> }
>
> Add in Smarty.class.php at the custom_mods array:
>
> 'ireplace' => 'smarty_mod_ireplace'
>
> Now you can use ireplace, just like the replace function.
>
> Regards,
> Joris
>
> ---
> You are currently subscribed to smarty as: monte@ispi.net
> To unsubscribe send a blank email to $subst('Email.Unsub')
> Visit Smarty's homepage at
> http://www.phpinsider.com/php/code/Smarty/
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/