在PHP对象中拆分数据

In the following code, is it possible to spilt the Object $author where white space occurs ?

<?php
$url="http://search.twitter.com/search.rss?q=laugh";
$twitter_xml = simplexml_load_file($url); 

foreach ($twitter_xml->channel->item as $key) {
 $a = $key->{"author"}; 
 echo $a;
}
?>

Use explode:

$array = explode(' ', $key->{"author"});

There is an explode function that can easily accomplish that. So, for example:

$a = $key->{"author"};
$author = explode(" ", $a);
$first_name = $author[0];
$last_name = $author[1];

Hope that helps.

$split =  explode(' ', (string) $key->{"author"}));

OR

$split = preg_split('/\s+/', (string) $key->{"author"}));

To split by @ just take $split and run in loop

 foreach($split as $key => $value) {
    $eta = explode('@', $value);
    var_dump($eta);
 }

To check if string exist use strpos

foreach($split as $key => $value) {
    if (strpos($value, '@') !== 0) echo 'found';
}

Assuming you merely care to get 2 parts: email, and "friendly name" (cause people have 1 to n number of names).

<?php
$url="http://search.twitter.com/search.rss?q=laugh";
$twitter_xml = simplexml_load_file($url);

foreach ($twitter_xml->channel->item as $key) {
 $a = $key->{"author"};
 preg_match("/([^ ]*) (.*)/", $a, $matches);
 print_r($matches);
 echo "
";
}
?>