我有一個腳本來閱讀Shoutcast直播信息。Php在閱讀頁面時刪除html標籤
我正在獲取曲目的名稱並在spotify api上搜索以獲得封面藝術。
我的代碼:
$sc_url_ip = "streamip";
$sc_url_port = "streamport";
function getNowPlaying($sc_url_ip,$sc_url_port)
{
$open = fsockopen($sc_url_ip,$sc_url_port,$errno,$errstr,'.5');
if ($open) {
fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n");
stream_set_timeout($open,'1');
$read = fread($open,200);
$text = explode(",",$read);
if($text[6] == '' || $text[6] == '</body></html>'){
$msg = ' live stream offline'; }
else {
$msg = $text[6];
}
$text = $msg;
}
else {
return false;
}
fclose($open);
return $text;
}
$current_song = getNowPlaying($sc_url_ip,$sc_url_port);
echo $current_song;
但隨着Spotify的API進行搜索時,我的曲目名稱看起來像這樣在源代碼:
Pink Floyd - Welcome to the Machine</body></html>
因爲HTML標籤,Spotify的API,搜索結果爲零。查看搜索網址:
我試圖用strip_tags,但我不能。 如何從$ current_song中刪除這些</body></html>
標籤?
你可以嘗試使用PHP的[strip_tags()](http://php.net/manual/en/function.strip-tags.php)。 –
是的,我試過了,但我不知道strip_tags到哪個變量 – Solhan
到包含曲目名稱的變量。將它添加到函數的返回中:'return strip_tags($ text);' –