SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Romania
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    Any ideeas? Thanks.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,185
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    array

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

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Romania
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

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

    I do not use smarty, but here is the code that will work in basic php.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Romania
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    SitePoint Addict
    Join Date
    Jul 2007
    Location
    San Jose, California
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •