Split a string and put on array

Discussion in 'PHP' started by KingCobra, Apr 17, 2013.

  1. #1
    Dear friends,

    I have a string like bellow:
    $string = "ABCDE  56.10 0.80    1.45%";
    PHP:
    I would like to remove all spaces and split and put on a arry something like bellow:
    $string[0] ; // output ABCDE
    $string[1] ; // output 56.10
    $string[2] ; // output 0.80
    $string[3] ; // output 1.45%

    Please help me. Thanks
     
    KingCobra, Apr 17, 2013 IP
  2. KingCobra

    KingCobra Well-Known Member

    Messages:
    289
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #2
    Dear friends, i solved the problem myself
    here is the code:
    $string = preg_split("/[\s,]+/", $code);
    print_r($string);
    // or
    echo "$string[0] $string[1] $string[2] $string[3]";
    PHP:
     
    KingCobra, Apr 17, 2013 IP