Smarty - Using foreach with explode

Hello,

I have the following text in a field that comes with another fields as a result of a query:

3_2007-07-17;5_2007-07-17;2_2007-07-17;

Using Smarty’s foreach and explode I would like to build links like:

http://www.mysite.com/page.php?id=3&date=2007-07-17
http://www.mysite.com/page.php?id=5&date=2007-07-17
http://www.mysite.com/page.php?id=2&date=2007-07-17

Any ideeas? Thanks.

It seems explode and foreach should work OK. What problems are you having? Posting a bit of the code might help.

I can’t display the date, it only displays the number. Here’s the code:

{assign var=analizeFirstTemp value=“;”|explode:$p[p].tip_analiza}
{foreach item=nrAnaliza from=$analizeFirstTemp name=nrAnaliza}
{assign var=analizeSecondTemp value=“_”|explode:$nrAnaliza}
{foreach item=analiza from=$analizeSecondTemp name=analiza}
{$analiza}
{/foreach}
{/foreach}

$p[p].tip_analiza is the field containg the data.



$dates = array();
$encoded_dates = explode( ";", $string_to_parse );
foreach( $encoded_dates as $date ) {
    $dates[] = substr($date, 3 );
}

I do not use smarty, but here is the code that will work in basic php.

I can’t use that code because the field that contains that data (3_2007-07-17;5_2007-07-17;2_2007-07-17;…) comes with another fields as a result of a query and the it’s passed to Smarty. So I must implement a Smarty ONLY solution.

Can you just extract the dates into their own variable then
$foo = substr("3_2007-07-17;5_2007-07-17;2_2007-07-17;…) ",0,35);
$dates = array();

$encoded_dates = explode( “;”, $string_to_parse );

foreach( $encoded_dates as $date ) {

$dates[] = substr($date, 3 );

}