gpt4 book ai didi

php - 如何使用 SimpleXML 获取具有命名空间的节点属性?

转载 作者:可可西里 更新时间:2023-10-31 23:57:32 24 4
gpt4 key购买 nike

<分区>

youtube.xml

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:gd="http://schemas.google.com/g/2005" xmlns:yt="http://gdata.youtube.com/schemas/2007">  

<entry>
...
<yt:duration seconds="1870"/>
...
</entry>

</feed>

update_videos.php

$source = 'youtube.xml';

// load as file
$youtube = new SimpleXMLElement($source, null, true);

foreach($youtube->entry as $item){
//title works
echo $item->title;

//now how to get seconds? My attempt...
$namespaces = $item->getNameSpaces(true);
$yt = $item->children($namespaces['yt']);
$seconds = $yt->duration->attributes();
echo $seconds['seconds'];
//but doesn't work :(
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com