我正在使用SimpleXML从公共提要@ Flickr中提取图像。我希望把所有拉到图像到一个数组中,我已经做了:通过foreach创建数组
$images = array();
foreach($channel->item as $item){
$url = $path->to->url;
$images[] = $url;
}
从这个话,我可以附和了所有的图像使用:
foreach($images as $image){
//output image
}
然后我决定我想有图像标题,以及用户,所以我认为我会用:
$images = array();
foreach($channel->item as $item){
$url = $path->to->url;
$title = $path->to->title;
$images[$title] = $url;
}
我想用我$image['name of title']
可输出为标题的URL,这将意味着,但它提供了一个非法的偏移误差,当我る这个..只会有标题和网址,但不是用户。
谷歌上搜索了一下我念你不能在数组键使用_
后,但我尝试使用:
$normal = 'dddd';
$illegal = ' de___eee';
$li[$normal] = 'Normal';
$li[$illegal] = 'Illegal';
而这种输出权,排除_
是在数组中的键非法(..我想) 。
所以现在我真的很困惑为什么它不会运行,当我在玩时使用print_r()
我注意到数组中的一些SimpleXML对象,这就是为什么我认为这是给出错误。
理想的输出将在格式的数组:
$image = array(0 => array('title'=>'title of image',
'user'=>'name of user',
'url' =>'url of image'),
1 => array(....)
);
但我真的难倒我怎么会从foreach
环路构成本,链接引用以及其他问题(couldn” t找到任何),欢迎。
谢谢你,我觉得很愚蠢。 – Daniel 2011-02-19 04:22:14