本文整理汇总了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;
}