简体   繁体   English

PHP对象-如何访问此值

[英]PHP Object - how can I access this value

I have this link http://lazhalazha.livejournal.com/data/rss with RSS in it, what I need to get is array of guid values, that is links to the post. 我有此链接http://lazhalazha.livejournal.com/data/rss其中包含RSS,我需要获取的是guid值数组,即该帖子的链接。 This is what I have so far... 这是我到目前为止所拥有的...

$xml = simplexml_load_file('http://lazhalazha.livejournal.com/data/rss');
foreach ($xml->channel->item as $item){
    print_r($item->guid);
}

Output is series of these objects 输出是这些对象的序列

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [isPermaLink] => true
        )

    [0] => http://lazhalazha.livejournal.com/713.html
)

Solved this by converting this object to string, then it's passing correct URL instead of object. 通过将此对象转换为字符串来解决此问题,然后它传递正确的URL而不是对象。

$xml = simplexml_load_file('http://lazhalazha.livejournal.com/data/rss');
$linkArray = array();
foreach ($xml->channel->item as $item){
    $guid = (string)$item->guid;
    array_push($linkArray, $guid);
}
<?php
$_temp = array();
$xml = simplexml_load_file('http://lazhalazha.livejournal.com/data/rss');

foreach ($xml->channel->item as $item){
    $_temp[] = (string)$item->guid[0];
}

print_r($_temp);
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM