PHP脚本回显正在播放XML属性的VLC
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP脚本回显正在播放XML属性的VLC,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4038字,纯文字阅读大概需要6分钟。
内容图文
![PHP脚本回显正在播放XML属性的VLC](/upload/InfoBanner/zyjiaocheng/690/32307e828b574253a1bbd34932bfd672.jpg)
我已经搜索了一段时间,运气还不太好.我已经找到了很多资源来展示如何从动态XML中回显数据,但是我是PHP新手,尽管我所听到的一切,它所写的内容似乎都无法完全抓住并打印出我想要的内容.相对容易.源XML(位于192.168.0.15:8080/requests/status.xml)如下:
<root>
<fullscreen>0</fullscreen>
<volume>97</volume>
<repeat>false</repeat>
<version>2.0.5 Twoflower</version>
<random>true</random>
<audiodelay>0</audiodelay>
<apiversion>3</apiversion>
<videoeffects>
<hue>0</hue>
<saturation>1</saturation>
<contrast>1</contrast>
<brightness>1</brightness>
<gamma>1</gamma>
</videoeffects>
<state>playing</state>
<loop>true</loop>
<time>37</time>
<position>0.22050105035305</position>
<rate>1</rate>
<length>168</length>
<subtitledelay>0</subtitledelay>
<equalizer/>
<information>
<category name="meta">
<info name="description">
000003EC 00000253 00000D98 000007C0 00009C57 00004E37 000068EB 00003DC5 00015F90 00011187
</info>
<info name="date">2003</info>
<info name="artwork_url"> file://brentonshp04/music%24/Music/Hackett%2C%20Steve/Guitar%20Noir%20%26%20There%20Are%20Many%20Sides%20to%20the%20Night%20Disc%202/Folder.jpg
</info>
<info name="artist">Steve Hackett</info>
<info name="publisher">Recall</info>
<info name="album">Guitar Noir & There Are Many Sides to the Night Disc 2
</info>
<info name="track_number">5</info>
<info name="title">Beja Flor [Live]</info>
<info name="genre">Rock</info>
<info name="filename">Beja Flor [Live]</info>
</category>
<category name="Stream 0">
<info name="Bitrate">128 kb/s</info>
<info name="Type">Audio</info>
<info name="Channels">Stereo</info>
<info name="Sample rate">44100 Hz</info>
<info name="Codec">MPEG Audio layer 1/2/3 (mpga)</info>
</category>
</information>
<stats>
<lostabuffers>0</lostabuffers>
<readpackets>568</readpackets>
<lostpictures>0</lostpictures>
<demuxreadbytes>580544</demuxreadbytes>
<demuxbitrate>0.015997290611267</demuxbitrate>
<playedabuffers>0</playedabuffers>
<demuxcorrupted>0</demuxcorrupted>
<sendbitrate>0</sendbitrate>
<sentbytes>0</sentbytes>
<displayedpictures>0</displayedpictures>
<demuxreadpackets>0</demuxreadpackets>
<sentpackets>0</sentpackets>
<inputbitrate>0.016695899888873</inputbitrate>
<demuxdiscontinuity>0</demuxdiscontinuity>
<averagedemuxbitrate>0</averagedemuxbitrate>
<decodedvideo>0</decodedvideo>
<averageinputbitrate>0</averageinputbitrate>
<readbytes>581844</readbytes>
<decodedaudio>0</decodedaudio>
</stats>
</root>
我要写的是一个简单的PHP脚本,它呼应艺术家的名字(在本例中为Steve Hackett).实际上,我希望它能与艺术家,歌曲和专辑相呼应,但是我有信心,如果我已展示如何检索其中的一个,我可以自己找出其余的东西.
我的脚本实际上似乎没什么用,如下.我已经尝试了许多工作,但我遗漏了一些事实,这些事实我都没有用.
<?PHP
$file = file_get_contents('http://192.168.0.15:8080/requests/status.xml');
$sxe = new SimpleXMLElement($file);
foreach($sxe->...
echo "Artist: "...
?>
我想我需要使用foreach和echo,但是我无法弄清楚该如何做才能打印出这些信息括号之间的内容.
抱歉,如果我遗漏了任何东西.我不仅是PHP的新手,还是StackOverflow的新手.我在其他项目中也引用了此站点,它总是非常有用,因此在此先感谢您的耐心和帮助!
/////////已完成的工作脚本-感谢Stefano和所有提供帮助的人!
<?PHP
$file = file_get_contents('http://192.168.0.15:8080/requests/status.xml');
$sxe = new SimpleXMLElement($file);
$artist_xpath = $sxe->xpath('//info[@name="artist"]');
$album_xpath = $sxe->xpath('//info[@name="album"]');
$title_xpath = $sxe->xpath('//info[@name="title"]');
$artist = (string) $artist_xpath[0];
$album = (string) $album_xpath[0];
$title = (string) $title_xpath[0];
echo "<B>Artist: </B>".$artist."</br>";
echo "<B>Title: </B>".$title."</br>";
echo "<B>Album: </B>".$album."</br>";
?>
解决方法:
除了使用for循环外,您还可以使用XPath获得相同的结果:
// Extraction splitted across two lines for clarity
$artist_xpath = $sxe->xpath('//info[@name="artist"]');
$artist = (string) $artist_xpath[0];
echo $artist;
您将不得不调整xpath表达式(即,适当地更改@name = …),但是您知道了.还要注意,[0]是必需的,因为xpath将返回一个匹配数组(并且您只需要第一个匹配项),并且强制类型转换(字符串)用于提取节点中包含的文本.
此外,您的XML无效,并且由于字面&语法,将被解析器拒绝.出现在< info name =“ album”>标签.
内容总结
以上是互联网集市为您收集整理的PHP脚本回显正在播放XML属性的VLC全部内容,希望文章能够帮你解决PHP脚本回显正在播放XML属性的VLC所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。