久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

        <bdo id='kmpqy'></bdo><ul id='kmpqy'></ul>

    1. <i id='kmpqy'><tr id='kmpqy'><dt id='kmpqy'><q id='kmpqy'><span id='kmpqy'><b id='kmpqy'><form id='kmpqy'><ins id='kmpqy'></ins><ul id='kmpqy'></ul><sub id='kmpqy'></sub></form><legend id='kmpqy'></legend><bdo id='kmpqy'><pre id='kmpqy'><center id='kmpqy'></center></pre></bdo></b><th id='kmpqy'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='kmpqy'><tfoot id='kmpqy'></tfoot><dl id='kmpqy'><fieldset id='kmpqy'></fieldset></dl></div>

      <small id='kmpqy'></small><noframes id='kmpqy'>

      1. <tfoot id='kmpqy'></tfoot>
      2. <legend id='kmpqy'><style id='kmpqy'><dir id='kmpqy'><q id='kmpqy'></q></dir></style></legend>

        僅從 php 中使用的 preg_match_all 的 html 表中獲取數

        Get data only from html table used preg_match_all in php(僅從 php 中使用的 preg_match_all 的 html 表中獲取數據)
          <bdo id='AMgEU'></bdo><ul id='AMgEU'></ul>
              <tbody id='AMgEU'></tbody>
            • <tfoot id='AMgEU'></tfoot>
              1. <legend id='AMgEU'><style id='AMgEU'><dir id='AMgEU'><q id='AMgEU'></q></dir></style></legend>

                <small id='AMgEU'></small><noframes id='AMgEU'>

                1. <i id='AMgEU'><tr id='AMgEU'><dt id='AMgEU'><q id='AMgEU'><span id='AMgEU'><b id='AMgEU'><form id='AMgEU'><ins id='AMgEU'></ins><ul id='AMgEU'></ul><sub id='AMgEU'></sub></form><legend id='AMgEU'></legend><bdo id='AMgEU'><pre id='AMgEU'><center id='AMgEU'></center></pre></bdo></b><th id='AMgEU'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='AMgEU'><tfoot id='AMgEU'></tfoot><dl id='AMgEU'><fieldset id='AMgEU'></fieldset></dl></div>
                  本文介紹了僅從 php 中使用的 preg_match_all 的 html 表中獲取數據的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個這樣的 html 表格:

                  I have a html table like this :

                  <table ... >
                  
                    <tbody ... >
                  
                         <tr ... > 
                               <td ...>
                                    string...
                                </td>
                                  <td ...>
                                    string...
                                </td>
                                  <td ...>
                                    string...
                                </td>
                                  <td ...>
                                    string...
                                </td>
                                  <td ...>
                                    string...
                                </td>
                         </tr>
                          <tr ... > 
                               <td ...>
                                    string...
                                </td>
                                  <td ...>
                                    string...
                                </td>
                                  <td ...>
                                    string...
                                </td>
                                  <td ...>
                               </td>
                                  <td ...>
                                    string...
                                </td>
                         </tr>
                         ..............
                  
                    </tbody>
                  
                  
                  </table>
                  

                  這是一個數據表,我需要從中獲取所有數據.該表將有許多行 ().每行都有一個固定的列()(目前是 5 ).記住每個表、tr、td 標簽可能已格式化(其中說...")

                  This is a data table and I need to get all data from this. The table will have many rows (<tr></tr>) . each row will have a fixed columns (<td></td>)(currently is 5 ). remember each table,tr,td tag maybe formatted (where say "...")

                  我希望大家能幫我寫一個正則表達式用于 preg_match_all 函數來獲取這樣的數據:

                  And I hope everyone can help me to write a regex for preg_match_all function to get the data like this :

                  array(
                     0 => array(
                         0=> 'some data0',
                         1=> 'some data1',
                         2=> 'some data2',
                         3=> 'some data3',
                         4=> 'some data4',
                     )
                     1 => array(
                         0=> 'some data0',
                         1=> 'some data1',
                         2=> 'some data2',
                         3=> 'some data3',
                         4=> 'some data4',
                     )
                     2 => array(
                         0=> 'some data0',
                         1=> 'some data1',
                         2=> 'some data2',
                         3=> 'some data3',
                         4=> 'some data4',
                     )
                  ..........
                  )
                  

                  現在是你的測試示例,希望你能幫助我?。?!

                  Now the example for your test, hopfully you can help me!!!

                  <table border="1" >
                    <tbody style="" >
                  
                         <tr style="" > 
                               <td style="color:blue;">
                                    data0
                                </td>
                                  <td style="font-size:15px;">
                                   data1
                                </td>
                                  <td style="font-size:15px;">
                                    data2
                                </td>
                                  <td style="color:blue;">
                                    data3
                                </td>
                                  <td style="color:blue;">
                                    data4
                                </td>
                         </tr>
                         <tr style="" > 
                               <td style="color:blue;">
                                    data00
                                </td>
                                  <td style="font-size:15px;">
                                   data11
                                </td>
                                  <td style="font-size:15px;">
                                    data22
                                </td>
                                  <td style="color:blue;">
                                    data33
                                </td>
                                  <td style="color:blue;">
                                    data44
                                </td>
                         </tr>
                         <tr style="color:black" > 
                               <td style="color:blue;">
                                    data000
                                </td>
                                  <td style="font-size:15px;">
                                   data111
                                </td>
                                  <td style="font-size:15px;">
                                    data222
                                </td>
                                  <td style="color:blue;">
                                    data333
                                </td>
                                  <td style="color:blue;">
                                    data444
                                </td>
                         </tr>
                  
                    </tbody>
                  
                  
                  </table>
                  

                  推薦答案

                  你絕對不想用 Regex 解析 HTML.

                  You absolutely do NOT want to parse HTML with Regex.

                  有太多的變體,一方面,更重要的是,正則表達式對于 HTML 的層次結構不是很好.最好使用 XML 解析器或更好的 HTML 特定解析器.

                  There are far too many variations, for one, and more importantly, regex isn't very good with the hierarchal nature of HTML. It's best to use an XML parser or better-yet an HTML-specific parser.

                  每當我需要抓取 HTML 時,我傾向于使用 Simple HTML DOM Parser 庫,它需要一個HTML 樹并將其解析為可遍歷的 PHP 對象,您可以在該對象中查詢類似 JQuery 的內容.

                  Whenever I need to scrape HTML, I tend to use the Simple HTML DOM Parser library, which takes an HTML tree and parses it into a traversable PHP object, which you can query something like JQuery.

                  <?php
                      require 'simplehtmldom/simple_html_dom.php';
                  
                      $sHtml = <<<EOS
                      <table border="1" >
                        <tbody style="" >
                             <tr style="" > 
                                   <td style="color:blue;">
                                        data0
                                    </td>
                                      <td style="font-size:15px;">
                                       data1
                                    </td>
                                      <td style="font-size:15px;">
                                        data2
                                    </td>
                                      <td style="color:blue;">
                                        data3
                                    </td>
                                      <td style="color:blue;">
                                        data4
                                    </td>
                             </tr>
                             <tr style="" > 
                                   <td style="color:blue;">
                                        data00
                                    </td>
                                      <td style="font-size:15px;">
                                       data11
                                    </td>
                                      <td style="font-size:15px;">
                                        data22
                                    </td>
                                      <td style="color:blue;">
                                        data33
                                    </td>
                                      <td style="color:blue;">
                                        data44
                                    </td>
                             </tr>
                             <tr style="color:black" > 
                                   <td style="color:blue;">
                                        data000
                                    </td>
                                      <td style="font-size:15px;">
                                       data111
                                    </td>
                                      <td style="font-size:15px;">
                                        data222
                                    </td>
                                      <td style="color:blue;">
                                        data333
                                    </td>
                                      <td style="color:blue;">
                                        data444
                                    </td>
                             </tr>
                        </tbody>
                      </table>
                  EOS;
                  
                      $oHTML = str_get_html($sHtml);
                      $oTRs = $oHTML->find('table tr');
                      $aData = array();
                      foreach($oTRs as $oTR) {
                          $aRow = array();
                          $oTDs = $oTR->find('td');
                  
                          foreach($oTDs as $oTD) {
                              $aRow[] = trim($oTD->plaintext);
                          }
                  
                          $aData[] = $aRow;
                      }
                  
                      var_dump($aData);
                  ?>
                  

                  和輸出:

                  array
                    0 => 
                      array
                        0 => string 'data0' (length=5)
                        1 => string 'data1' (length=5)
                        2 => string 'data2' (length=5)
                        3 => string 'data3' (length=5)
                        4 => string 'data4' (length=5)
                    1 => 
                      array
                        0 => string 'data00' (length=6)
                        1 => string 'data11' (length=6)
                        2 => string 'data22' (length=6)
                        3 => string 'data33' (length=6)
                        4 => string 'data44' (length=6)
                    2 => 
                      array
                        0 => string 'data000' (length=7)
                        1 => string 'data111' (length=7)
                        2 => string 'data222' (length=7)
                        3 => string 'data333' (length=7)
                        4 => string 'data444' (length=7)
                  

                  這篇關于僅從 php 中使用的 preg_match_all 的 html 表中獲取數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

                    <tfoot id='ZaWrL'></tfoot>
                  • <legend id='ZaWrL'><style id='ZaWrL'><dir id='ZaWrL'><q id='ZaWrL'></q></dir></style></legend>
                  • <i id='ZaWrL'><tr id='ZaWrL'><dt id='ZaWrL'><q id='ZaWrL'><span id='ZaWrL'><b id='ZaWrL'><form id='ZaWrL'><ins id='ZaWrL'></ins><ul id='ZaWrL'></ul><sub id='ZaWrL'></sub></form><legend id='ZaWrL'></legend><bdo id='ZaWrL'><pre id='ZaWrL'><center id='ZaWrL'></center></pre></bdo></b><th id='ZaWrL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ZaWrL'><tfoot id='ZaWrL'></tfoot><dl id='ZaWrL'><fieldset id='ZaWrL'></fieldset></dl></div>
                        <bdo id='ZaWrL'></bdo><ul id='ZaWrL'></ul>

                            <tbody id='ZaWrL'></tbody>

                          1. <small id='ZaWrL'></small><noframes id='ZaWrL'>

                            主站蜘蛛池模板: 日韩精品一区二区三区中文字幕 | 国产9久 | 日韩和的一区二区 | 日本 欧美 国产 | 九九精品久久久 | 亚洲国产网站 | 成人精品视频99在线观看免费 | 操操日 | www.毛片| 久久亚洲欧美日韩精品专区 | 久久88| 日韩成人精品一区 | 欧美综合在线观看 | 99国内精品 | 国产一区二区精品自拍 | 99成人精品 | 亚洲国产精品久久 | 午夜精品久久久久久久99黑人 | 99精品在线 | 亚洲成人动漫在线观看 | 国产精品久久久久久福利一牛影视 | 精品国产精品三级精品av网址 | 午夜影院视频在线观看 | 欧美在线成人影院 | 91精产国品一二三区 | 久久性色| 日韩精品一二三 | 成人性视频在线播放 | 免费看黄色视屏 | 日韩中文字幕一区二区 | 日韩欧美国产一区二区 | 日日骑| 91精品国产91久久久久久三级 | 伊人久久在线观看 | 丁香婷婷在线视频 | 国产成人免费在线 | 精品欧美二区 | 99国产在线 | 欧美国产精品久久久 | 亚洲97| 亚洲精选一区二区 |