Sorry for posting something not specifically CMSMS-related, but I have searched high and low in the Smarty manual as well as elsewhere online, and can't find an answer. As the post title says, I'm looking for a way to split a string with Smarty. I have a string "abc,def,ghi,jkl", and I want to split it at the commas, into an array.
I'm sure this is possible, so I must be searching using the wrong keywords.
I'm thinking it's probably something like
$var = abc,def,ghi,jkl
myArray = split{",", $var}
myArray[0] = 1
etc
Any help? Thanks a lot!!
How to split a string with Smarty [SOLVED]
How to split a string with Smarty [SOLVED]
Last edited by jmcgin51 on Sun Jul 05, 2009 11:00 pm, edited 1 time in total.
Re: How to split a string with Smarty
From Smarty site:
{assign var="teststring" value="31|32"}
{assign var="testsplit" value="|"|explode:$teststring}
{$testsplit[0]}
{$testsplit[1]}
produces:
31
32
Nullig
{assign var="teststring" value="31|32"}
{assign var="testsplit" value="|"|explode:$teststring}
{$testsplit[0]}
{$testsplit[1]}
produces:
31
32
Nullig
Re: How to split a string with Smarty
thanks Nullig! I had seen that example on the Smarty site, and tried it, but it didn't appear to do what I wanted. I'll give it another try, and see if I can beat it into submission.
Thanks again!
Thanks again!
Re: How to split a string with Smarty
worked perfectly - don't know what my problem was the first time!
Thanks again!!
Thanks again!!