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

WBOY
풀어 주다: 2016-06-06 20:38:24
원래의
1137명이 탐색했습니다.

如何用这个获取

<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

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!