2012-06-23 82 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