Re: Re: spliting the elements in array

From: Date: Wed, 04 Jul 2007 13:57:54 +0000
Subject: Re: Re: spliting the elements in array
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-258239@lists.php.net to get a copy of this message
Stut skrev:
sivasakthi wrote:
Thanks for your response.. Actually i have the collections of strings like, $not_quite_an_array = 'squid %tu %tl %mt %>A test %st.%hs %>a %<m %tu %th %Hs %Ss test1 %tv %tr %Hs.%Ss %mt'; from that i need to split name of each line..
$names = array(); foreach (explode("\n", $not_quite_an_array) as $line) {
    $line = trim($line);
    if (strlen($line) == 0) continue;
    $names[] = array_shift(explode(' ', $line, 2));
} -Stut
Or: $result = preg_match_all("/\s*([^\s]+)(?:\n|.*)/", $not_quite_an_array, $out); $names = array_pop( $out ); -- /Thunis I think you ought to know I'm feeling very depressed. --The Hitchikers Guide to the Galaxy

« previous php.general (#258239) next »