Hello,
I have the following text in a field that comes with another fields as a result of a query:Using Smarty's foreach and explode I would like to build links like:3_2007-07-17;5_2007-07-17;2_2007-07-17;
Any ideeas? Thanks.
| SitePoint Sponsor |

Hello,
I have the following text in a field that comes with another fields as a result of a query:Using Smarty's foreach and explode I would like to build links like:3_2007-07-17;5_2007-07-17;2_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:
$p[p].tip_analiza is the field containg the data.{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}



I do not use smarty, but here is the code that will work in basic php.PHP Code:
$dates = array();
$encoded_dates = explode( ";", $string_to_parse );
foreach( $encoded_dates as $date ) {
$dates[] = substr($date, 3 );
}
Computers and Fire ...
In the hands of the inexperienced or uneducated,
the results can be disastrous.
While the professional can tame, master even conquer.

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 );
}
Bookmarks