Results 1 to 2 of 2

Thread: Splitting a sting into individual chars

  1. #1
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Splitting a sting into individual chars

    Hi,

    I have been trying to split up a number string with PHP into individual chars but have had no luck so far. I have used str_split and according to the manual what I'm doing should work, but it isn't.

    Bascially what I have is this:

    PHP Code:

    $dateFormat 
    str_split($row[DATE], 1);            
    echo 
    $dateFormat[0]; echo $dateFormat[1]; echo "/"; echo $dateFormat[2]; echo $dateFormat[3]; echo "/"; echo $dateFormat[4]; echo $dateFormat[5]; echo $dateFormat[6]; echo $dateFormat[7]; 
    $row[DATE] is a string for the date which comes out of the database, for example, it could be: 15072012. I need it to be in this format for other processes I have running in the background, but what I need for this process is for 15072012 to be re-formatted to 15/07/2012.

    Any pointers or guidance would be appreciated.

    Thanks! :-)

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    I don't get it, the code is working just fine. I tested it like so:
    PHP Code:
    $dateFormat str_split("15072012"1);            
    echo 
    $dateFormat[0]; echo $dateFormat[1]; echo "/"; echo $dateFormat[2]; echo $dateFormat[3]; echo "/"; echo $dateFormat[4]; echo $dateFormat[5]; echo $dateFormat[6]; echo $dateFormat[7]; 
    and it returned: 15/07/2012

    Is it possible that your $row[DATE] is null in the instance that you tried it? Try looking at that as your problem.
    - Josh

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
  •