2016-08-04 28 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解析器,也有一些图书馆出来的互联网。