Hello everybody,

I need to retrieve some informations on a static webpage to save them in a file. I use the file_get_contents function to grab the page and then strpos to set the coordonates. Here is my code :

<?php
$newstring = file_get_contents("http://www.mywebsite/page.html"); // Recover the target webpage
$pos = strpos($newstring, 'class="my_specific_class"><a href='); // Find the beginning tag of a specific element 
$posout = strpos($newstring, '</a> (<a href=/'); // Find the end tag of the specific element 
$pos = $pos+62; // Start position
$result = substr($newstring, $pos, $posout-$pos); // Webpage + Start position + Endposition
echo $result; // Print the result
?>

Everything just works fine, I grab the word I need, but there are many other words on the same page I need too, and they all use the same class ('class="my_specific_class">).
So I'm looking for a way to build a loop and retrieve all the elements of the page.
I don't really know where I have to start. Any help will be a lot appreciate.

Thanks a lot !

    PHP DOM will let you do that easily.

    $dom = new DOMDocument()
    $dom->loadHTML() / $dom->loadHTMLFile()
    $elements = $dom->getElementsByTagName('div or whatever');
    foreach($elements as $e)
    	// check if it's the correct class
    
      Write a Reply...