I have some HTML that is setup like the following (this can be different though!):
<table></table>
<h4>Content</h4>
<table></table>
I'm using PHP Simple HTML DOM Parser to loop over a section of code setup like this:
How can I say something like - "Find the table and the preceding h4, grab the text from the h4 if it exists, if it doesn't then leave blank".
If I just use $html->find('div[class=product-table] h4'); then it ignores the fact there was no title for the first table.
This is my full code for context:
$table_rows = $html->find('div[class=product-table] table');
$tablecounter = 1;
foreach ($table_rows as $table){
$tablevalue[] =
array(
"field_5b3f40cae191b" => "Table",
);
}
update_field( $field_key, $tablevalue, $post_id );
Update:
I've found in the documentation that you can use prev_sibling() so I've tried $table_title = $html->find('div[class=product-table] table')->prev_sibling('h4'); but can't seem to get it to work.
