Jump to content

[SOLVED] parse help


richiec

Recommended Posts

Hey, i am quite new to php and i have been stuck on this topic now for a few days and i can not seem to get my head around it so any help you guys can give me will be of great help and much appreciated.

 

This is what i am trying to do.

 

a code which will parse a specified URL for a table name and then print everything back that it finds within that table.

 

Thanks

 

Rich.

Link to comment
Share on other sites

So you are looking to get the contents of another website, find a table within that website, and print out that particular table?

 

Depending on the website you are getting the contents from, you can either use file_get_contents() or you may have to use cURL and php. Once you have the contents of the page in a variable, you will need to use regular expressions to find your particular table. The preg_match() function is what you'll need.

 

To be able to give you any more help, we're probably going to need a bit more detail.

Link to comment
Share on other sites

<?php
$file = file_get_contents("http://outwar.com");

list($before, $after) = split("<table tag here>">, $file);
list($table) = split("</end table tag here", $after);

echo $table;
?>

 

There is an example, replace what you are searching for in the first parameter of www.php.net/split

Link to comment
Share on other sites

Frost100 - i really dont think its going to be that simple. If you take a look at the website, there is very little on it - im guessing the table that is wanted is a table you can only see once logged in. In which case, cURL will be needed.

 

Probably not, but that part doesn't matter to me whether he gets it from cURL or not. He asked for an example to his question, that is how you would parse a remote site.

 

Either way it is an example, if he has to use curl the same would apply, you would just have to use curl commands to get the data off the page.

 

Maybe next time he will learn to ask the right question better if he needs to login etc. He just asked how do you parse a table from a webpage. =)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.