How to split a string with Smarty [SOLVED]

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

How to split a string with Smarty [SOLVED]

Post by jmcgin51 »

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!!
Last edited by jmcgin51 on Sun Jul 05, 2009 11:00 pm, edited 1 time in total.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: How to split a string with Smarty

Post by Nullig »

From Smarty site:

{assign var="teststring" value="31|32"}
{assign var="testsplit" value="|"|explode:$teststring}
{$testsplit[0]}

{$testsplit[1]}

produces:

31
32

Nullig
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: How to split a string with Smarty

Post by jmcgin51 »

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!
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: How to split a string with Smarty

Post by jmcgin51 »

worked perfectly - don't know what my problem was the first time!

Thanks again!!
Post Reply

Return to “The Lounge”