Re: how to do a ireplace

From: Date: Thu, 08 Feb 2001 16:17:03 +0000
Subject: Re: how to do a ireplace
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-93@lists.php.net to get a copy of this message
Joris Trooster / Interstroom wrote: > > (sorry for the wrong subject in the order mail) > > A variable modifier "ireplace" would be nice for case insensitive replace. > Unfortunately there is no stri_replace in PHP 4. However it can be done > by using reg_replace("/$search/i", $replace, $string); > in your custom made variable modifier (ireplace) in Smarty. > > Joris This could be done, or pass an optional third parameter to replace. Which would be best for Smarty, or for the template designer? On a technical note, if $search contains a slash "/" or any special character for pattern matching, you would get an error or undesirable results. Use preg_quote() to get around it. $string = preg_replace("/".preg_quote($search),"/", $replace, $string);

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