Advanced Search

Results 1 to 4 of 4

Thread: help with converting string ..

  1. #1
    Join Date
    Sep 2009
    Posts
    44
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question help with converting string ..

    Hi im a php newbie

    i have this code

    PHP Code:
    <?
    $noic 
    "811009-xx-xxxx";
    $ex explode('-',$noic);
    $sp str_split($ex[0]);

    $year $sp[0].$sp[1];
    $month $sp[2].$sp[3];
    $day $sp[4].$sp[5];

    echo 
    $day.'-'.$month.'-'.$year;

    ?>

    it will change noic = 811009-xx-xxxx to date 09-10-81

    what if my noic is in this format 811009xxxxxx

    how do i do this..

    TQ

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    27,558
    Thanks
    42
    Thanked 2,879 Times in 2,851 Posts
    Blog Entries
    12

    Default

    PHP Code:
    <?php
        $noic 
    "811009-xx-xxxx"
        
    $sp substr($noic06); 

        
    $year $sp[0].$sp[1]; 
        
    $month $sp[2].$sp[3]; 
        
    $day $sp[4].$sp[5]; 

        echo 
    $day.'-'.$month.'-'.$year;
    ?>
    See:

    http://www.php.net/manual/en/function.substr.php
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Sep 2009
    Posts
    44
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    thank you bro..

    youre the man..

    i love php :-)

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,138
    Thanks
    61
    Thanked 438 Times in 427 Posts
    Blog Entries
    7

    Default

    Note that if you use a more standard date format, you can use the DateTime class, which is designed for exactly this task.
    Adrian ~ facebook | gist/github

    ['66.215.156.37','208.75.149.97'] // ip,ip array!
    "Take that sticker *off* your hat; you look stupid" --Wil Wheaton

Similar Threads

  1. Resolved converting string to an octal number
    By james438 in forum PHP
    Replies: 4
    Last Post: 11-27-2011, 07:27 PM
  2. Append string to the end of string via a loop
    By l_kris06 in forum JavaScript
    Replies: 1
    Last Post: 06-24-2009, 02:59 PM
  3. Resolved parseInt() is still recognizing string as string only
    By JShor in forum JavaScript
    Replies: 3
    Last Post: 06-21-2009, 12:14 AM
  4. converting AS2.0 to 3.0
    By mossawi in forum Flash
    Replies: 1
    Last Post: 06-04-2009, 10:55 PM
  5. Need help converting string to formula
    By Falkon303 in forum JavaScript
    Replies: 12
    Last Post: 02-17-2009, 03:58 PM

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
  •