Why not just put it into an array and then you can format it any way you want. This is an old script that still works...
<?php
// $html would be the Status Report you want to process!
// sub string from where we need our data to where our data ends...
// start
$html = substr ( $html, stripos ( $html, 'the status' ) );
// end
$html = substr ( $html, 0, strripos ( $html, '<br><br>' ) );
// setup the html... (get it ready to convert);
$regex = array ( '#<th.*>#Uis', '#<tr.*>#Uis',
'#<td.*>#Uis', '#<\/?table.*>#Uis',
'#<\/th.*><\/tr.*>#Uis', '# #Uis',
'#<\/tr.*>#Uis', '#<\/td.*>#Uis' );
$replace = array ( '<th>', '<tr>',
'<td>', '',
'', '',
'</tr>', '</td>' );
$html = preg_replace ( $regex, $replace, $html );
// split the data up starting at each title element (header)
$parts = explode ( '<tr><th>', $html );
// set our output container
$out = array ();
// set our main header text
$out['header'] = strip_tags ( $parts[0] );
// remove $parts[0] = (our header text) and reset the $parts array!
array_shift ( $parts );
// now build our data array
foreach ( $parts AS $data )
{
// split the data fields (IE: <td>name</td>||<td>value</td>)
$data = str_replace ( '</td><td>', '</td>||<td>', $data );
// create a new data array for each new (<tr><td>)
$data = explode ( '<tr><td>', $data );
// the first element $data[0] is always the header for this data block
$header = trim ( array_shift ( $data ) );
// go through each <TR> tag set (IE: <tr><td>? = name</td><td>? = value</td</tr>)
foreach ( $data AS $item )
{
// get the name value pairs
list ( $name, $value ) = array_map ( 'trim', explode ( '</td>||<td>', substr ( $item, 0, strpos ( $item, '</td></tr>' ) ) ) );
// there is one case where the structure may cause a false positive, so we catch it here...
if ( ! empty ( $name ) && ! empty ( $value ) )
{
$out[$header][$name] = $value;
}
}
}
// print out the result array...
print_r ( $out );
?>
It will output this...
Array
(
[header] => The status of the Republic of Canyon Land (#750).
[The Basics] => Array
(
[Turns Left] => 10
[Turns Taken] => 2938
[Rank] => 38
[Networth] => $18,143,148
)
[Current Status] => Array
(
[Money] => $238,681,220
[Population] => 501,921
[Land] => 18865 Acres
[Food] => 2,165,120 bushels
[Production] => 7 bushels
[Consumption] => 23,525 bushels
[Net Change] => -23,518 bushels
[Oil] => 1,140,920 barrels
)
[Economics] => Array
(
[Tax Revenues] => $10,375,953
[Tax Rate] => 35%
[Per Capita Income] => $59.06
[Expenses] => $4,419,146
[Military] => $4,112,567
[Alliance/GDI] => $117,929
[Land] => $188,650
[Net Income] => $5,956,807
)
[Land Distribution] => Array
(
[Enterprise Zones] => 8663
[Residences] => 8663
[Industrial Complexes] => 260
[Military Bases] => 960
[Construction Sites] => 300
[Unused Lands] => 19
)
[Military Forces] => Array
(
[Spies] => 218,990
[Troops] => 4,807,197
[Jets] => 9,142,002
[Turrets] => 4,348,609
[Tanks] => 1,328,015
[Nuclear Missiles] => 5
[Chemical Missiles] => 12
[Cruise Missiles] => 9
)
[Technology] => Array
(
[Military] => 288,889
[Medical] => 18,716
[Business] => 508,812
[Residential] => 509,326
[Agricultural] => 2316
[Warfare] => 2931
[Military Strategy] => 9334
[Weapons] => 827
[Industrial] => 8651
[Spy] => 3587
[SDI] => 190,345
)
)