I have a file “import.php” in which html data is written under table tags. Now i want to parse that data and save that data in an excel sheet. Format is undermentioned and first tr contains the heading and then the data
<html>
<body>
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Addr</th>
<th>City</th>
</tr>
<tr>
<td>Jack</td>
<td>a@b.com</td>
<td>xyz Road</td>
<td>LOS ANGELES</td>
</tr>
<tr>
<td>Sam</td>
<td>sam@b.com</td>
<td>pr Road</td>
<td>TUSTIN</td>
</tr>
</table>
</body>
</html>
Maybe you’ve better look at this: http://phpexcel.codeplex.com/
and this: http://www.easyxls.com/
Another trick is to save your data as a CSV file: http://www.homeandlearn.co.uk/php/php10p6.html
UPDATE:
There is no simpler way for saving data into an Excel file directly but saving as CSV. Try this code:
As for the seperation of the values from the html tags, you could read your html code from import.php, remove all unnecessary tags, put a seperator to the end of each or tag and then put your values into a single dimension array:
The first 4 values of the array $values contain your header values. Hope that it helps…