1

您好,我正在寻找一些 html 并将其显示在另一个页面上。我正在做一个直播服务器,我想从 7.html 中获取歌曲标题,但我只需要歌曲的标题。只是我尝试过 fsockopen 的注释,但我的网络主机阻止了它,所以我无法连接并获取这样的歌曲标题。

html 的源代码如下所示

<HTML><meta http-equiv="Pragma" content="no-cache"></head><body>0,1,0,5000,0,96,SONG TITLE HERE</body></html>

我只需要显示“SONG TITLE HERE”我将如何仅将该信息设置为 php 变量

我知道下面的方法,但这里的问题是它会得到一切。我只需要源html的一部分。

<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
4

3 回答 3

2
<?php
    $doc = new DOMDocument;
    $doc->loadhtmlfile('http://www.example.com/');

    $body = $doc->getElementsByTagName('body');
    $content = $body->item(0)->textContent;

    $arr = explode(',', $content);

    $song = end($arr);
?>
于 2013-04-13T22:07:46.367 回答
1

尝试这样的事情:

<?php
$content = file_get_contenst("7.html");
$dom = new DOMDocument();
$dom->loadHTML($content);

$body = $dom->getElementsByTagName('body');

$info = $body->item(0)->nodeValue;

$infoArr = str_getcsv($info);

$title = array_pop($infoArr);
?>

有很多方法可以处理这个。你也可以使用这样的东西:

preg_match("/<body>(.*?)<\/body>/i", $html, $matches);

而不是 DOMDocument。或explode() 而不是str_getcsv()。

于 2013-04-13T22:06:09.193 回答
0

我能够使用 iframe 从服务器的 7.html 中获取所有内容

adeneo 答案本来可以完美的,但是我的主机不允许我以这种方式连接到其他服务器。

于 2013-05-05T20:12:11.423 回答