-1

Possible Duplicate:
Best methods to parse HTML with PHP

I'm using the file_get_contents() function in PHP to retrieve a remote webpage and run it into my table parsing script. But basically, my table parsing script only takes the first table on the page.

The page I'm trying to download has 3 html tables in it, so I was wondering if there was a way of only taking the third table? Most likely I'd want to only take lines 30 to 60 in the HTML file. Does anyone have any suggestions?

Community
  • 1
  • 1
Shane
  • 23
  • 2
  • 9

2 Answers2

0

There is no file downloading command that will parse a HTML file for you, and determine the exact chunk that needs to be downloaded. I don't think there is a way around downloading the whole thing, and using a HTML parser to fetch the table afterwards.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
0

You could split your main file up into three separate files (once for each table) which just get 'included' into the original.

Then you will just need to do a file_get_contents for the table that you want.

Edit

As an example, consider this file:

 <h1>I am a header</h1>
 <table id = 'table1>
 ...
 </table>

 <table id = 'table2'>
 ...
 </table>

 <table id = 'table3'>
 ...
 </table>

And compare it with this file:

<h1>I am a header</h1> 
<?php
    include 'table1.php';
    include 'table2.php';
    include 'table3.php'; 
?>

table1.php will simply hold everything between the table tags for table 1, and similarly for table2.php and table3.php.

If you want table 3, perform your file_get_contents on table3.php

Jeff Lambert
  • 24,395
  • 4
  • 69
  • 96