2016-08-04 59 views
0

我正在嘗試獲取表格選項值,特別是下面的「每頁數」值。通過PHP獲取HTML表格選項值

<table class="centerTable" number-per-page="3" current-page="0"> 

我需要使用php獲取每頁數的選項值。這可能嗎?如果有幫助,我使用內聯php。

回答

1

如前所述由answer到類似的問題,你可以使用:

$str = <table class='centerTable' number-per-page='3' current-page="0"> 
$doc = new DOMDocument(); 
$d  = $doc->loadHtml($str); 
$tbl = $doc->getElementsByTagName('table'); # select table 
$attr = $tbl->getAttribute('number-per-page'); # get attribute value 

另外,如果你添加一個id到你的表,你也可以用它來選擇它:

$tbl = $doc->getElementById('your-table-id'); 

欲瞭解更多信息,請參閱PHP DOM documentation

0

您可以嘗試preg_match

preg_match('/<table.[^>]*number-per-page="(\d+)".[^>]*>/im', $html, $match); 
$number_per_page = $match[1]; 

您也可以嘗試的PHP的HTML解析器,也有一些圖書館出來的互聯網。