Home >Backend Development >PHP Tutorial >有大神用过PHP Simple HTML DOM Parser这个吗 求指教

有大神用过PHP Simple HTML DOM Parser这个吗 求指教

WBOY
WBOYOriginal
2016-06-06 20:38:241174browse

如何用这个获取

<code><table width="100%" border="0" cellpadding="0" cellspacing="0" class="titleTop2">
    <tr>
        <td class="pageAlign">
            <table cellpadding="0" width="100%" class="displayTag" cellspacing="1" border="0" id="user">
                <thead>
                    <tr>
                        <th align="center" width="10%" class="sortable">课程号</th>


<p>获取到  课程号   这三个字</p>

                            
                        


                                                                                                                        
                     <h2>回复内容:</h2>
                      
                                                            
<p>如何用这个获取</p>

<pre class="brush:php;toolbar:false"><code><table width="100%" border="0" cellpadding="0" cellspacing="0" class="titleTop2">
    <tr>
        <td class="pageAlign">
            <table cellpadding="0" width="100%" class="displayTag" cellspacing="1" border="0" id="user">
                <thead>
                    <tr>
                        <th align="center" width="10%" class="sortable">课程号</th>


<p>获取到  课程号   这三个字</p>

                            
                        
            <p class="answer fmt" data-id="1020000002529999">
                                    
</p>
<pre class="brush:php;toolbar:false"><code>php</code><code><br>$html = >>>XML


<table>
<th align="center" width="10%" class="sortable">
                课程号
                </th>
</table>


XML

$xml = simplexml_load_string($html)

$ths = $xml->xpath("/table/th/[@category='sortable']")

print_r($ths[0])

// 课程号
</code>

顺便给你找了一条 xpath 资料

如果你使用过 jquery 的话,可以试试 phpQuery

<code>$html = "<table>...</table>";
$htmlObject = str_get_html($html);
$th = $htmlObject->find('th', 0);
$text = $th->plaintext;
</code>

官方文档,实例详尽:http://simplehtmldom.sourceforge.net/manual.htm

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn