Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts

    how to loop the exploded variables

    hello anyone could help me how loop this code below..

    list($day,$month,$year)=explode('/',$_POST['startdate']);
    echo $start=$year.'-'.$month.'-'.$day;
    list($day,$month,$year)=explode('/',$_POST['completiondate']);
    echo $completion=$year.'-'.$month.'-'.$day;
    list($day,$month,$year)=explode('/',$_POST['interviewdate']);
    echo $interview=$year.'-'.$month.'-'.$day;


    tnx..

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    You could use a function:

    PHP Code:
    function convertDate($date){
    list(
    $day,$month,$year)=explode('/',$date);
    return 
    $year.'-'.$month.'-'.$day;
    }

    echo 
    convertDate($_POST['startdate']);
    echo 
    convertDate($_POST['completiondate']);
    echo 
    convertDate($_POST['interviewdate']); 
    Last edited by Mwnciau; 08-31-2007 at 11:33 AM.

  • #3
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts
    I noticed a space with the result in the second value of $_POST[completiondate]..

    2007-08-01
    2007 -08-02 //space in year 2007 -08
    2007-08-03


    tnx.

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    26
    Thanks
    0
    Thanked 4 Times in 4 Posts
    PHP Code:
    $_POST['firstname']         = 'firstname';
    $_POST['lastname']          = 'lastname';
    $_POST['startdate']         = '19/10/1976';
    $_POST['completiondate']    = '26/12/1950';
    $_POST['interviewdate']     = '17/12/2005';

    foreach (
    $_POST as $key => $val)
    {
        
    $tmp explode('/',$_POST[$key]);
        if (
    count($tmp) == 3)
        {
            
    $_POST[$key] = $tmp[2] .'-'$tmp[1] .'-'$tmp[0];
        }    
    }

    foreach (
    $_POST as $key => $val)
    {
        echo 
    "<p>$key = $val";

    Last edited by Bahamut; 08-31-2007 at 12:03 PM.

  • Users who have thanked Bahamut for this post:

    che_anj (08-31-2007)

  • #5
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    function convertDate($date){
    list(
    $day,$month,$year)=explode('/',$date);
    return 
    trim($year).'-'.trim($month).'-'.trim($day);
    }

    echo 
    convertDate($_POST['startdate']);
    echo 
    convertDate($_POST['completiondate']);
    echo 
    convertDate($_POST['interviewdate']); 
    That should get rid of any spaces

    Quote Originally Posted by che_anj View Post
    I noticed a space with the result in the second value of $_POST[completiondate]..

    2007-08-01
    2007 -08-02 //space in year 2007 -08
    2007-08-03


    tnx.

  • Users who have thanked Mwnciau for this post:

    che_anj (08-31-2007)

  • #6
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts
    tnx guys.. you have different ideas but it all works...


  •  

    Posting Permissions

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