好的,所以即时通讯使用tumblr的API,即时通讯使用SimpleXMLElement和PHP,我遇到了问题。
基本上,当我调用变量时,它只会打印一个零。
例如:
<?php echo $data->posts->post[0]->photo-url[5]; ?>
这只会破坏页面,当我省略[5]时,它只会打印零
我想用数字[5]来回复照片网址,但是我无法理解这个并且杀了我。我只是不明白为什么它不会工作。
下面是simpleXMLElement打印输出的示例:
SimpleXMLElement Object
( [@attributes] =&gt;排列 ( [版本] =&gt; 1.0 )
[posts] => SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => photo
)
[post] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 574166180
[url] => http://young-n-reckless.tumblr.com/post/574166180
[url-with-slug] => http://young-n-reckless.tumblr.com/post/574166180
[type] => photo
[date-gmt] => 2010-05-05 19:52:46 GMT
[date] => Wed, 05 May 2010 15:52:46
[unix-timestamp] => 1273089166
[format] => html
[reblog-key] => vc9EfT7d
[slug] =>
[tumblelog] => young-n-reckless
[bookmarklet] => true
)
[tumblelog] => SimpleXMLElement Object
(
[@attributes] => Array
(
[title] => Young & Reckless
[name] => young-n-reckless
[url] => http://young-n-reckless.tumblr.com/
[timezone] => US/Eastern
[avatar-url-16] => http://24.media.tumblr.com/avatar_424f776dd55c_16.png
[avatar-url-24] => http://24.media.tumblr.com/avatar_424f776dd55c_24.png
[avatar-url-30] => http://24.media.tumblr.com/avatar_424f776dd55c_30.png
[avatar-url-40] => http://25.media.tumblr.com/avatar_424f776dd55c_40.png
[avatar-url-48] => http://24.media.tumblr.com/avatar_424f776dd55c_48.png
[avatar-url-64] => http://26.media.tumblr.com/avatar_424f776dd55c_64.png
[avatar-url-96] => http://25.media.tumblr.com/avatar_424f776dd55c_96.png
[avatar-url-128] => http://24.media.tumblr.com/avatar_424f776dd55c_128.png
[avatar-url-512] => http://29.media.tumblr.com/avatar_424f776dd55c_512.png
)
)
[photo-link-url] => http://www.flickr.com/photos/katiemabey/3429588812/
[photo-url] => Array
(
[0] => http://30.media.tumblr.com/tumblr_l1w1qd7Zcg1qatgoto1_500.jpg
[1] => http://30.media.tumblr.com/tumblr_l1w1qd7Zcg1qatgoto1_500.jpg
[2] => http://25.media.tumblr.com/tumblr_l1w1qd7Zcg1qatgoto1_400.jpg
[3] => http://28.media.tumblr.com/tumblr_l1w1qd7Zcg1qatgoto1_250.jpg
[4] => http://30.media.tumblr.com/tumblr_l1w1qd7Zcg1qatgoto1_100.jpg
[5] => http://30.media.tumblr.com/tumblr_l1w1qd7Zcg1qatgoto1_75sq.jpg
)
)
非常感谢任何帮助,并提前感谢。 沃伦
答案 0 :(得分:1)
如果元素名称中包含破折号,则需要将其包裹起来:
<?php echo $data->posts->post[0]->{'photo-url'}[5]; ?>