I Have a smarty variable, I want to know if it matches some string like
"<whatever>_thestring_<whatever>"
where <whatever>
represents any sequence of characters (or no characters).
Is there some way to test against something like *_thestring_*
?
Using smarty to check if a string exists inside another string:
{assign "haystack1" "whatever_thestring_whatever"}
{assign "haystack2" "whatever_thestrings_whatever"}
Test haystack1 {if $haystack1|strstr:"_thestring_"}Found!{/if}<br />
Test haystack2 {if $haystack2|strstr:"_thestring_"}Found!{/if}<br /><br />
Output:
Test haystack1 Found!
Test haystack2
Or you could do a more complex search using Regex in smarty:
{assign "haystack1" "whatever_thestring_whatever"}
{assign "haystack2" "whatever_thestrings_whatever"}
{assign "check_haystack1" $haystack1|regex_replace:"/_thestring_/":" "}
{assign "check_haystack2" $haystack2|regex_replace:"/_thestring_/":" "}
Test haystack1 {if $check_haystack1 !== $haystack1}Found!{/if}<br />
Test haystack2 {if $check_haystack2 !== $haystack2}Found!{/if}<br />
Which has the output:
Test haystack1 Found!
Test haystack2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With