I want to extract table from html page which contains nested html table tags after that I want to extract <td>
and <tr>
of tables.
I am using this. Its working fine for <b>
and </b>
$file = file_get_contents($url);
preg_match_all ("/<b>(.*)<\/b>/U", $file, $pat_array);
print $pat_array[0][0]." <br> ".$pat_array[0][1]."\n";
Can anybody tell me regular expression for nested <table (some table properties)>
some data using <tr>
and <td> </table>
. Please keep the href if present in the <tr>
or <td>
fields, and keep in mind the needed tables.
Example:
$file = "<html> <head> <title> asdf </title> </head> <body bgcolor = red > <table border = 1> <table bgcolor = white> (some tr and td data > </table> </table></body> </body> </html>"
preg_match_all ("regular expression for table tag", $file, $pat_array);
print $pat_array[0][0]." <br> ".$pat_array[0][1]."\n";
Update 1 :
When I tried below code it shows the error:
Notice: Undefined offset: 0 in C:\xampp\htdocs\testphp\tabledata.php on line 27
Code:
$file = file_get_contents($url);
$pat_array = Array();
preg_match_all ("/<tr>(.*)<\/tr>/U", $file, $pat_array);
print $pat_array[1][0];
Can anybody help me regarding this error also?