Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   PHP, PERL, MySQL, JavaScript (https://forum.antichat.xyz/forumdisplay.php?f=37)
-   -   Массив (https://forum.antichat.xyz/showthread.php?t=84714)

OdaN 13.09.2008 20:36

Массив
 
Народ, подскажите плз, как php`ой разбить текст на массив по строкам? т.е. есть
PHP код:

$var="qwe\n
asd\n
zxc\n"


а нать
Код:

Array
(
    [0] => qwe
    [1] => asd
    [2] => zxc
)


BlackSun 13.09.2008 20:41

PHP код:

function text2array($var)
{
    
$result null;
    
    
$tok strtok($var"\n");
    while (
$tok)
    {
        
$tok strtok("\n");
        
$result[] = $tok;
    }
    
    return 
$result;


// так, вы этого не видели, это глюки .. :p

razzzar 13.09.2008 20:43

BlackSun о ужас :)

$res = explode("\n", $var);

FrMn 13.09.2008 20:46

PHP код:

<?php
$var
="qwe\nasd\nzxc\n";
$arr=explode("\n",$var);
print_r($arr);
?>

---опередил


Время: 23:20