Re: [SMARTY] fuzzy comparisons

From: Date: Wed, 15 Jan 2003 15:38:33 +0000
Subject: Re: [SMARTY] fuzzy comparisons
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-7190@lists.php.net to get a copy of this message
Thanks!!! I looked EVERYWHERE for a "trim" modifier, so that is very useful information. (That PHP string functions become smarty modifiers, I mean.) And to think I was about to resign myself to writing a plugin. :-) cheers, Travis Jeff Dickens wrote:
try this: {assign var=var1 value="stuff"} {assign var=var2 value="stuff "} {assign var=var2a value=$var2|trim} {if $var1 = $var2a} They match. {else} They don't. {/if} I still haven't figured out where it says that all php functions are transparently imported as smarty modifiers, but a apparently they are. (i.e. trim isn't in the smarty docs)
-----Original Message----- From: Travis Low [mailto:travis@dawnstar.org] Sent: Wednesday, January 15, 2003 10:03 AM To: smarty-general@lists.php.net Subject: [SMARTY] fuzzy comparisons I'd like to compare two strings in the template, and take one action if they are the same, and another action if they are not. One string comes from an XML file. The other string comes from a CSV file. I cannot (easily) manipulate the strings from within PHP, because I'd have to do all of them, or none of them. It turns out that sometimes one or the other string has leading or trailing spaces. This makes the comparison evaluate to false, which is a problem. I tried doing this: {if $string1|replace:" ":"" == $string2|replace:" ":""} but that caused a template error. I also tried this: {assign var=s1 value=$string1|replace:" ":""} {assign var=s2 value=$string2|replace:" ":""} {if $s1 == $s2} ... {/if} but I got an error that way too. Any suggestions? Thanks in advance. cheers, Travis -- Travis Low <mailto:travis@dawnstar.org> <http://dawnstar.org/travis> -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- Travis Low <mailto:travis@dawnstar.org> <http://dawnstar.org/travis>

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