0
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

        <html xmlns="http://www.w3.org/1999/xhtml">
        <head id="Head1"><title>
            Online-Edu-Help.com
        </title></head>

        <body>
            <form name="form1" method="post" action="Post.aspx" id="form1">
        <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTYxNTMxOTk3MGRkTKiZyXxt1USQVFZyWkCnecSqXls=" />

            <span id="lblError"></span>
            <span id="lblNoError">Accepted: 3231401</span>
            <br /> </form>
        </body>
        </html>

我想从 php 中的 html 响应中解析 lblError 和 lblNoError 的值。

4

1 回答 1

0
        <?php
        $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

        <html xmlns="http://www.w3.org/1999/xhtml">
        <head id="Head1"><title>
            Online-Edu-Help.com
        </title></head>

        <body>
            <form name="form1" method="post" action="Post.aspx" id="form1">
        <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTYxNTMxOTk3MGRkTKiZyXxt1USQVFZyWkCnecSqXls=" />

            <span id="lblError"></span>
            <span id="lblNoError">Accepted: 3231401</span>
            <br /> </form>
        </body>
        </html>';
        $dom = new DomDocument();
        $dom->loadHTML($html);

        $lblNoError = $dom->getElementById('lblNoError'); 
            echo $lblNoErrorvalue = $lblNoError->nodeValue;
        $lblError = $dom->getElementById('lblError'); 
            echo $lblErrorvalue = $lblError->nodeValue;
        ?>
于 2014-10-15T13:31:29.163 回答