I want to get contents of cell which contains ID as MainCell.HTML Code:<table > <tr> <td></td> </tr> <tr> <td class=\"Contents\"> <p>Large Paragraph1....</p> <p>Large Paragraph1....</p> <p>Large Paragraph1....</p> <p>Large Paragraph1....</p> </td> <tr> <td class=\"Contents\"> <p>Large Paragraph 2</p> <p>Large Paragraph 2</p> <p>Large Paragraph 2</p> <p>Large Paragraph 2</p> <p>Large Paragraph 2</p> </td> </tr> </table>
So I have wrote a sample php code like this
But this is not working, What's wrong on this code?PHP Code:
<?php $html="<table >
<tr>
<td></td>
</tr>
<tr>
<td class=\"Contents\">
<p>Large Paragraph1....</p>
<p>Large Paragraph1....</p>
<p>Large Paragraph1....</p>
<p>Large Paragraph1....</p>
</td>
<tr>
<td class=\"Contents\">
<p>Large Paragraph 2</p>
<p>Large Paragraph 2</p>
<p>Large Paragraph 2</p>
<p>Large Paragraph 2</p>
<p>Large Paragraph 2</p>
</td>
</tr>
</table>";
preg_match_all('#<td class=\"Contents\">(.+?)</td>#', $html, $MainHeads);
echo "<table>";
foreach ($MainHeads[1] as $Contents)
{
echo("<tr>");
echo("<td>.$Contents.</td>");
echo("</tr>");
}
echo "</table>";
?>
Note: When I change $html like this
It is workingPHP Code:$html="<table >
<tr>
<td></td>
</tr>
<tr>
<td class=\"Contents\"><p>Large Paragraph1....</p></td>
<tr>
<td class=\"Contents\"><p>Large Paragraph 2</p></td>
</tr>
</table>";




Reply With Quote