2012-06-23 84 views
0

我需要嵌入的SoundCloud网址在我的网站,所以我要求网站用户提交他们希望嵌入自己的网页获取用户ID

上的SoundCloud网址有没有什么办法可以使用在iframe PHP 1.价值URL的SRC 2.内和用户ID,即822654

<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> 

我试图parse_url(PHP函数),但无法取得我想要的 如果有人可以帮助我也知道每个用户是否获得847884这样的id(在上面的情况下)或者嵌入代码可能具有虚荣URL(比如而不是847884用户可以拥有/ bob/or/andrew /)?

回答

1

脚本:

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

看到它,测试它here

+0

谢谢你的帮助,它有效 – June