【问题标题】:Remotely get soundcloud ID using DOM使用 DOM 远程获取 soundcloud ID
【发布时间】:2011-09-19 23:30:03
【问题描述】:

我想通过它的 url 嵌入 soundcloud http://soundcloud.com/oembed?url=http://soundcloud.com/kiwinest/linkin-park-iridescent 这个网址提供了声音文件的每一个细节,包括 html 嵌入代码 所以我只想删除所有代码并想要 17181143 的声音 ID 我正在使用此代码

<?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;
                    }
                }
            }
        }
    }
}

但这不会有任何输出..!! (空白)

【问题讨论】:

    标签: php dom embed soundcloud working-remotely


    【解决方案1】:

    应该同意我的回答:-D。确保 $html 不为空;就像确保您实际上从该 URL 中获取了一些东西,并且它存储在该变量中。我的回答比他疯狂的大 O 噩梦还要短。因此,如果您看到数字 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];
    

    【讨论】:

    • 是的,感谢您回复您的代码效果很好,但有 8 位数字..!!你能告诉我soundcloud是否可以有大于8位的ID..!!上次我尝试您的代码时,它会显示声音 id 2 次​​span>
    • @user809307 k,我更改了代码。 8,15 表示长度介于 8 位和 15 位之间。
    猜你喜欢
    • 1970-01-01
    • 2019-07-04
    • 2017-04-20
    • 1970-01-01
    • 2022-12-05
    • 2016-03-25
    • 2015-06-18
    • 1970-01-01
    • 2018-12-08
    相关资源
    最近更新 更多