Parsing a PHP String without Delimiters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AttilaTheChris

    Parsing a PHP String without Delimiters

    I'm trying to figure out how to parse the MySQL Date/Time group
    '20031001155704 ' into meaningful data (i.e. - year, month, day, hour,
    minute, and second).

    Is there a built-in PHP string function that does this?

    Thanks,
    Chris
  • Douglas Abernathy

    #2
    Re: Parsing a PHP String without Delimiters


    "AttilaTheChris " <cmh_jobs@yahoo .com> wrote in message
    news:e1facc8a.0 310011331.37ae4 b1e@posting.goo gle.com...[color=blue]
    > I'm trying to figure out how to parse the MySQL Date/Time group
    > '20031001155704 ' into meaningful data (i.e. - year, month, day, hour,
    > minute, and second).
    >
    > Is there a built-in PHP string function that does this?
    >
    > Thanks,
    > Chris[/color]

    The function you are searching for is sscanf.

    Try this code (just paste this into a file as is):

    <?
    //Parse of time format
    $textstring = "20031001155704 ";
    $result = sscanf($textstr ing,"%4s%2s%2s% 2s%2s%2s");
    list($year,$mon th,$day,$hour,$ minute,$second) = $result;
    print "<html>\n<head> \n</head>\n<body>\n ";
    print "The original string is\n<pre>$texts tring\n</pre>\n";
    print "Year = $year\n";
    print "Month = $month\n";
    print "Day = $day\n";
    print "Hour = $hour\n";
    print "Minute = $minute\n";
    print "Second = $second\n";
    print "</body>\n</html>\n";
    ?>

    Douglas Abernathy


    Comment

    Working...