获取跨度值的PHP Dom解析器

获取跨度值的PHP Dom解析器,php,parsing,dom,Php,Parsing,Dom,我希望从外部URL收集信息,并将其剥离到值 比如说 <span id="ctl00_cphRoblox_rbxUserStatisticsPane_lFriendsStatistics">149</span> 149 我找不到使用PHPDOM获取'149'的方法 请帮忙,谢谢 function DOMRemove(DOMNode $from) { $sibling = $from->firstChild; do { $next =

我希望从外部URL收集信息,并将其剥离到值

比如说

<span id="ctl00_cphRoblox_rbxUserStatisticsPane_lFriendsStatistics">149</span>
149
我找不到使用PHPDOM获取'149'的方法

请帮忙,谢谢

function DOMRemove(DOMNode $from) {
    $sibling = $from->firstChild;
    do {
        $next = $sibling->nextSibling;
        $from->parentNode->insertBefore($sibling, $from);
    } while ($sibling = $next);
    $from->parentNode->removeChild($from);    
}

$dom = new DOMDocument;
$dom->load('test.html');

$nodes = $dom->getElementsByTagName('span');
foreach ($nodes as $node) {
    DOMRemove($node);
}
echo $dom->saveHTML();
资料来源:

  • 还有:有一个库可以解析PHP的HTML
资料来源:

  • 还有:有一个库可以解析PHP的HTML
一种方法是使用
preg\u match()
,但我只会将其与curl()一起使用


第三种方法是使用内置DOMDocument。

一种方法是使用
preg_match()
,但我只会将它与curl()一起使用

第三种方法是使用内置DOMDocument

$row = '<span id="ctl00_cphRoblox_rbxUserStatisticsPane_lFriendsStatistics">149</span>';
preg_match_all('/<span.*?>.*?<\/[\s]*span>/s', $row, $matches2);
var_dump($matches2);
include('simple_html_dom.php');
$html = str_get_html($row);

var_dump($html->find('span', 0)->plaintext);