<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## 安裝 `composer require bupt1987/html-parser` ## 使用 ``` $html = '<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>test</title> </head> <body> <p class="test_class test_class1">p1_content</p> <p class="test_class test_class2">p2_content</p> <p class="test_class test_class3">p3_content</p> <div class="img"><img src="http://httpbin.org/image/jpeg" alt=""></div> <div id="test1">test1_content</div> </body> </html>'; $html_dom = new \HtmlParser\ParserDom($html); $p_array = $html_dom->find('p.test_class'); $p1 = $html_dom->find('p.test_class1',0);//取第一個 $div = $html_dom->find('div#test1',0); foreach ($p_array as $p){ echo $p->getPlainText() . "\n";//1.p1_content 2.p3_content 3.p3_content } echo $div->getPlainText() . "\n"; //test1_content echo $p1->getPlainText() . "\n"; //p1_content echo $p1->getAttr('class') . "\n"; //test_class test_class1 echo "show html:\n"; echo $div->innerHtml() . "\n";//test1_content $imgdiv = $html_dom->find(".img",0); echo $imgdiv->getAttr("data-test").PHP_EOL; //img_data echo $imgdiv->getPlainText().PHP_EOL;//img_content ``` ### 基礎用法 ``` // 查找所有a標簽 $ret = $html->find('a'); // 查找a標簽的第一個元素 $ret = $html->find('a', 0); // 查找a標簽的倒數第一個元素 $ret = $html->find('a', -1); // 查找所有含有id屬性的div標簽 $ret = $html->find('div[id]'); // 查找所有含有id屬性為foo的div標簽 $ret = $html->find('div[id=foo]'); ``` ### 層級選擇器 ``` // Find all <li> in <ul> $es = $html->find('ul li'); // Find Nested <div> tags $es = $html->find('div div div'); // Find all <td> in <table> which class=hello $es = $html->find('table.hello td'); // Find all td tags with attribite align=center in table tags $es = $html->find('table td[align=center]'); ``` ### 嵌套選擇器 ``` // Find all <li> in <ul> foreach($html->find('ul') as $ul) { foreach($ul->find('li') as $li) { // do something... } } // Find first <li> in first <ul> $e = $html->find('ul', 0)->find('li', 0); ``` ### 屬性過濾 ``` 支持屬性選擇器操作: 過濾 描述 [attribute] 匹配具有指定屬性的元素. [!attribute] 匹配不具有指定屬性的元素。 [attribute=value] 匹配具有指定屬性值的元素 [attribute!=value] 匹配不具有指定屬性值的元素 [attribute^=value] 匹配具有指定屬性值開始的元素 [attribute$=value] 匹配具有指定屬性值結束的元素 [attribute*=value] 匹配具有指定屬性的元素,且該屬性包含了一定的值 ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看