Split HTML tr elements into PHP array -


i've posted thread never explained well, deleted , rewriting it.

my php script sends curl request website output html table, use table has 7 tr elements in it, each tr element have 6 td elements within it.

this means html table technically coded on page, want split each tr separate php array, td's accessible through key.

so example:

table
-- tr1
----td
----td
----td
----td
----td
----td
-- tr2
----td
----td
----td
----td
----td
----td

i able do: echo $trarray[1][3]
echo 'td' because value of 2nd td element on first tr array

i'm not sure if explaining well, want able do

any appreciated!

make sure php have php-dom enabled:

$export = array(); $dom = new domdocument(); libxml_use_internal_errors(true); $dom->loadhtml($html); libxml_clear_errors();  $xpath = new domxpath($dom);  $tr_no = 0; foreach( $xpath->evaluate('//tr') $sel ){     $export[$tr_no] = array();     $td_no = 0;     foreach( $sel->childnodes $td ){        if( strtolower( $td->tagname )  == 'td' ){             $innerhtml = '';             foreach ($td->childnodes $child){                 $innerhtml .= $td->ownerdocument->savehtml($child);             }             $export[$tr_no][$td_no] = $innerhtml;             $td_no++;        }     }     $tr_no++; }  var_dump( $export ); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -