Php 从Soundcloud嵌入代码获取用户id
我需要在我的网站中嵌入soundcloud url,所以我要求网站用户提交他们希望嵌入到页面中的soundcloud url 有什么方法可以让我使用PHP吗 1.src内iframe中url的值 2.以及用户id,即822654Php 从Soundcloud嵌入代码获取用户id,php,regex,soundcloud,Php,Regex,Soundcloud,我需要在我的网站中嵌入soundcloud url,所以我要求网站用户提交他们希望嵌入到页面中的soundcloud url 有什么方法可以让我使用PHP吗 1.src内iframe中url的值 2.以及用户id,即822654 <iframe width="100%" height="450" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundclo
<iframe width="100%" height="450" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Fusers%2F847884 &show_artwork=true"></iframe>
我尝试解析url(PHP函数),但未能获取所需内容
如果有人能帮我知道,无论是每个用户都有一个像847884这样的id(在上面的例子中),还是嵌入的代码都可能有一个虚荣url(比如用户可以有/bob/或/andrew/而不是847884)?脚本:
查看并测试它
<?php
$subject = "<iframe width=\"100%\" height=\"450\" scrolling=\"no\" frameborder=\"no\" src=\"http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Fusers%2F847884&show_artwork=true\"></iframe>";
$pattern = '/<iframe[^>]*\ssrc="[^"]*\?url=([^&]*%2Fusers%2F(\d+)[^&]*)&/';
preg_match($pattern, $subject, $matches);
echo urldecode($matches[1]), "\n";
echo $matches[2], "\n";
?>
http://api.soundcloud.com/users/847884
847884