I have a problem, I have to make a Parser of a Web page. The structure is as follows:
<TABLE WIDTH=80%>
<tr><td colspan=7><BR><BR></td></tr>
<TR>
<Td colspan=7><FONT FACE="arial" align=left><B><A NAME="TEST">Anagrafica</B><br></TH>
</TR>
<tr><td colspan=7></td></tr>
<TR>
<TH ALIGN=LEFT ><FONT COLOR="#AA0000" FACE="arial" SIZE="2">Name</FONT></TH>
<TH></TH>
<TH ALIGN=LEFT ><FONT COLOR="#AA0000" FACE="arial" SIZE="2">Surname</FONT></TH>
<TH></TH>
<TH ALIGN=LEFT ><FONT COLOR="#AA0000" FACE="arial" SIZE="2">ID</FONT></TH>
<TH></TH>
<TH ALIGN=LEFT ><FONT COLOR="#AA0000" FACE="arial" SIZE="2">Code</FONT></TH>
</TR>
<tr>
<TD COLSPAN="7">
<HR SIZE="1" NOSHADE></TD>
<TR>
<TR>
<TD ALIGN="left" VALIGN="TOP" NOWRAP><FONT SIZE="1" FACE="arial">Mario</FONT> </TD>
<TD WIDTH="10"><VALIGN="TOP"><FONT SIZE="1" FACE="arial"> </FONT></TD>
<TD ALIGN="CENTER" VALIGN="TOP" NOWRAP><P ALIGN="CENTER"><FONT SIZE="1" FACE="arial"> Mario </FONT></TD>
<TD WIDTH="10"><VALIGN="TOP"><FONT SIZE="1" FACE="arial"> </FONT></TD>
<TD ALIGN="LEFT" VALIGN="TOP" NOWRAP><FONT SIZE="1" FACE="arial">1</FONT></TD>
<TD WIDTH="10"><VALIGN="TOP"><FONT SIZE="1" FACE="arial">a</FONT></TD>
<TD ALIGN="LEFT" VALIGN="TOP" NOWRAP><FONT SIZE="1" FACE="arial">132</FONT></TD>
<TR>
<TD ALIGN="left" VALIGN="TOP" NOWRAP><FONT SIZE="1" FACE="arial">Mario</FONT> </TD>
<TD WIDTH="10"><VALIGN="TOP"><FONT SIZE="1" FACE="arial"> </FONT></TD>
<TD ALIGN="CENTER" VALIGN="TOP" NOWRAP><P ALIGN="CENTER"><FONT SIZE="1" FACE="arial"> Mario </FONT></TD>
<TD WIDTH="10"><VALIGN="TOP"><FONT SIZE="1" FACE="arial"> </FONT></TD>
<TD ALIGN="LEFT" VALIGN="TOP" NOWRAP><FONT SIZE="1" FACE="arial">1</FONT></TD>
<TD WIDTH="10"><VALIGN="TOP"><FONT SIZE="1" FACE="arial">a</FONT></TD>
<TD ALIGN="LEFT" VALIGN="TOP" NOWRAP><FONT SIZE="1" FACE="arial">132</FONT></TD>
<TR>
I want to take the data of the 4 columns using this script
$start = strpos($content,'<Td colspan=7><FONT FACE="arial" align=left><B><A NAME=');
if ($start == TRUE) {
$end = strpos($content,'</TABLE>',$start) + 8;
$table = substr($content,$start,$end-$start);
preg_match_all("|<TD(.*)</TD>|U",$table,$rows);
$x = 1;
$counter = 1;
echo "<table class=\"TFtable\">";
foreach ($rows[0] as $row){
if ((strpos($row,'<TR')===false)){
preg_match_all("|<TD(.*)</TD>|U",$row,$cells);
$status[$x] = strip_tags($cells[0][0]);
$x = $x+1;
$counter = $counter+1;
}
if ($counter % 7 == 1) {
echo "<tr><td>{$status[2]} - {$status[4]} <br> {$status[6]} - {$status[1]}</td></tr>\n";
$x = 1;
}
}
echo "</table>";
In this way, however, the last field $ status [1] I will appear in the second row as if indeed it were part of line 2:
example
Mario Rossi 1 213
Mario Bianchi 2 324
Displaying
Mario Rossi 1
Mario Bianchi 2 213
Where am I wrong?