如何解决使用DOM远程获取soundcloud ID
| 我想通过它的网址嵌入soundcloud http://soundcloud.com/oembed?url=http://soundcloud.com/kiwinest/linkin-park-iridescent 该网址提供了声音文件的所有详细信息,包括html嵌入代码 所以我只想删除所有代码,并想要声音ID为17181143 我正在使用此代码<?php
include(\'lib/simple_html_dom.php\');
$html = file_get_html(\'http://soundcloud.com/oembed?url=http://soundcloud.com/kiwinest/linkin-park-iridescent\');
if ($html) {
foreach ($html->find(\'object\') as $obj) {
foreach ($obj->find(\'param\') as $par) {
if ($par->name == \'movie\') {
$embed = parse_url($par->value);
parse_str(urldecode($embed[\'query\']),$val);
if (array_key_exists(\'url\',$val)) {
$url = parse_url($val[\'url\']);
$path = explode(\'/\',$url[\'path\']);
$code = array_pop($path);
if (is_numeric($code)) {
echo \'CODE: \' . $code . PHP_EOL;
}
}
}
}
}
}
但是这将使输出什么都没有.. !! (空白)
解决方法
应该与我的答案:-D。确保$ html不为空;如要确保您确实从该URL得到了一些东西并将其存储在该变量中。我的回答比他疯狂的大噩梦还短。因此,如果您看到数字8,15(如下),则表示匹配8位数至15位数之间的数字。我更改了下面的代码。
include(\'lib/simple_html_dom.php\');
$html = file_get_html(\'http://soundcloud.com/oembed?url=http://soundcloud.com/kiwinest/linkin-park-iridescent\');
preg_match_all(\'/[0-9]{8,15}/\',$my_string,$ids);
echo $ids[0];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。