Массив

Discussion in 'PHP' started by OdaN, 13 Sep 2008.

  1. OdaN

    OdaN Elder - Старейшина

    Joined:
    4 Mar 2006
    Messages:
    192
    Likes Received:
    17
    Reputations:
    1
    Народ, подскажите плз, как php`ой разбить текст на массив по строкам? т.е. есть
    PHP:
    $var="qwe\n
    asd\n
    zxc\n"
    ;
    а нать
    Code:
    Array
    (
        [0] => qwe
        [1] => asd
        [2] => zxc
    )
     
  2. BlackSun

    BlackSun Banned

    Joined:
    1 Apr 2007
    Messages:
    989
    Likes Received:
    1,168
    Reputations:
    446
    PHP:
    function text2array($var)
    {
        
    $result null;
        
        
    $tok strtok($var"\n");
        while (
    $tok)
        {
            
    $tok strtok("\n");
            
    $result[] = $tok;
        }
        
        return 
    $result;
    }
    // так, вы этого не видели, это глюки .. :p
     
    #2 BlackSun, 13 Sep 2008
    Last edited: 13 Sep 2008
    3 people like this.
  3. razzzar

    razzzar Elder - Старейшина

    Joined:
    16 Jun 2007
    Messages:
    92
    Likes Received:
    75
    Reputations:
    5
    BlackSun о ужас :)

    $res = explode("\n", $var);
     
    4 people like this.
  4. FrMn

    FrMn Elder - Старейшина

    Joined:
    8 Aug 2008
    Messages:
    51
    Likes Received:
    16
    Reputations:
    7
    PHP:
    <?php
    $var
    ="qwe\nasd\nzxc\n";
    $arr=explode("\n",$var);
    print_r($arr);
    ?>
    ---опередил
     
    1 person likes this.