當前位置: 首頁>>代碼示例>>PHP>>正文


PHP HTMLTable::extractTablesHTML方法代碼示例

本文整理匯總了PHP中HTMLTable::extractTablesHTML方法的典型用法代碼示例。如果您正苦於以下問題:PHP HTMLTable::extractTablesHTML方法的具體用法?PHP HTMLTable::extractTablesHTML怎麽用?PHP HTMLTable::extractTablesHTML使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在HTMLTable的用法示例。


在下文中一共展示了HTMLTable::extractTablesHTML方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: extractTableHTML

 /**
  * Extract table market from an HTML document starting from $target.
  * Search for $target and extract the table $numShifts after the text.
  * If $numShifts is negative, counts backwards.
  *
  * example: Extract table containing anchor: ($src,$target,-1)
  * example: Extract very next table after anchor: ($src,$target,0)
  * example: Skip next table, extract second: ($src,$target,1)
  *
  * @param string &$src Given HTML to search.
  * @param string $target What to look for in html (case insensitive)
  * @param int $numShifts Number of tables to count.
  * @return string HTML containing the requested table.
  */
 function extractTableHTML(&$src, $target, $numShifts = 0)
 {
     $start = stripos($src, $target);
     if ($start === false) {
         return false;
     }
     if ($numShifts >= 0) {
         // Find tables after anchor
         do {
             $start = stripos($src, '<table', $start + 1);
             $numShifts -= 1;
         } while ($numShifts >= 0 && $start !== false);
         if ($start !== false) {
             $tmp = substr($src, $start);
             $tabs = HTMLTable::extractTablesHTML($tmp);
             return count($tabs) > 0 ? $tabs[0] : false;
         }
     } else {
         // find tables before anchor
         $stack = array();
         $ix = -1;
         while ($ix !== false && $ix <= $start) {
             $ix = stripos($src, '<table', $ix + 1);
             $stack[] = $ix;
         }
         array_pop($stack);
         $top = false;
         while (!empty($stack) && $numShifts < 0) {
             $top = array_pop($stack);
             $numShifts += 1;
         }
         if ($top !== false && $numShifts >= 0) {
             $tmp = substr($src, $top);
             $tabs = HTMLTable::extractTablesHTML($tmp);
             return count($tabs) > 0 ? $tabs[0] : false;
         }
     }
     return false;
 }
開發者ID:mukmuk623,項目名稱:stock-ticker-list,代碼行數:53,代碼來源:HTMLTable.php


注:本文中的HTMLTable::extractTablesHTML方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。