X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   smarty help please? can I compare the first x characters of a variable? (https://forum.x-cart.com/showthread.php?t=35861)

carpeperdiem 12-02-2007 09:46 PM

smarty help please? can I compare the first x characters of a variable?
 
Smarty help, please?

I am seeking to compare the first x characters of a var string - for example:

let's says there's a variable: $variablename

{if $variablename 1st 5 characetrs = 1ZAB1}
then show something
{else}
show something else.

Can this be done in smarty?

My goal is to trap the first 5 characters of a tracking number -- and if it looks like 1ZAB1, then it is clearly UPS, and I will show a UPS tracking link. ELSE it can only be USPS (and a different tracking link)

Any ideas?

Thanks.

Jeremy

inebriate 12-02-2007 09:49 PM

Re: smarty help please? can I compare the first x characters of a variable?
 
{if $variablename|substr:0:5 eq '1ZAB1'}

carpeperdiem 12-02-2007 09:57 PM

Re: smarty help please? can I compare the first x characters of a variable?
 
Quote:

{if $variablename|substr:0:5 eq '1ZAB1'}

that is just BEAUTIFUL!

thank you!

Jeremy

carpeperdiem 12-02-2007 10:34 PM

Re: smarty help please? can I compare the first x characters of a variable?
 
question: can the substr be case iNSEnsiTIvE?

so: if the string is 1zAb12v41234567

OR the string is:

1ZAB12V41234567

the results are the same?

is the there a smarty "case doesn't matter" setting?

thx

Jeremy

Ene 12-02-2007 11:22 PM

Re: smarty help please? can I compare the first x characters of a variable?
 
PHP Code:

{if $variablename|substr:0:5|upper eq '1ZAB1'



All times are GMT -8. The time now is 07:04 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.