Extracting Data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Extracting Data

Post 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)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Thanks alot feyd I will have a try, much appreciated!
Post Reply