Page 1 of 1

Extracting Data

Posted: Thu Jul 22, 2004 12:25 pm
by Joe
Is there anyway to extract certain data from an html form using php.
For example if I had:

Code: Select all

<html>
<body>
<table width="500"  cellpadding=3 border=0>
<tr>
<td>Joe Joe</td>
<td>8 Times Street, WorldGlobe</td>
</tr>
</html>
</body>
And I wanted to extract everything which was in between the <td> </td> tags. This is a project where I want to extract the data from uploaded files into the mysql database so any help appreciated.


Joe 8)

Posted: Thu Jul 22, 2004 12:28 pm
by feyd
regular expressions...

Code: Select all

<?php

preg_match_all('#<\s*td[^>]*?>(.*?)<\s*/\s*td[^>]*?>#i',$html,$matches);
print_r($matches[1]);

?>
that doesn't cover nested tables though... so be careful..

Posted: Thu Jul 22, 2004 12:32 pm
by Joe
Thanks alot feyd I will have a try, much appreciated!