0

I am trying to get a table option value, specifically the value of "number-per-page" below.

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

I need to get the number-per-page option value using php. Is this possible? I am using in-line php if that helps.

2 Answers2

0

You may try preg_match:

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

You may also try a HTML parser for php, there are some libraries out the internet.

Eduardo Escobar
  • 3,301
  • 2
  • 18
  • 15
0

As mentioned by an answer to a similar question, you can use:

$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

Alternately, if you add an id to your table, you can also use this to select it:

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

For more information, refer PHP DOM documentation.

Community
  • 1
  • 1
Surfine
  • 96
  • 4