0

Possible Duplicate:
How do you parse and process HTML/XML in PHP?

Currently I have a snippet of code that looks like this:

    echo '<div id="content">';
    echo '<b>Results:<br></b>';
    echo '<div style="margin-right: 230px; margin-top: -20px;"><center><a href="http://clubpenguincheatsnow.com/tools/itemdatabase/"><b>Back</b></a><center></div>';
    $string = explode('<br>', $string);
    foreach ($string as $row) {
        preg_match('/^(.+)\s=\s(\d+)\s=\s(\D+)\s=\s(\d+)/', trim($row), $matches);
        if (preg_match("/$query/i", "$matches[1]")) {
            echo "<a href='http://clubpenguincheatsnow.com/tools/itemdatabase/info.php?id=$matches[2]'>";
            echo $matches[1];
            echo "</a><br>";
        }
    }
    echo '</div>';

As you can see I have the div tags at the top and bottom echo '<div id="content">'; echo '</div>';. What I want to do is my PHP code to scan the output that is between the two tags, and if the text <b>Results:<br></b><div style="margin-right: 230px; margin-top: -20px;"><center><a href="http://clubpenguincheatsnow.com/tools/itemdatabase/"><b>Back</b></a><center></div> is between the tags I want my code to output "Test." Any help regarding my problem would be very helpful!

Community
  • 1
  • 1
S17514
  • 265
  • 2
  • 7
  • 16

2 Answers2

2

Consider the PHP Simple HTML DOM Parser for getting data from HTML.

WWW
  • 9,734
  • 1
  • 29
  • 33
-1

If you feel comfortable with Regex, you can use it when the page remains pretty much static. This site can help you build regex queries. Otherwise, try and use Simple HTML DOM wherever possible as mentioned above. You'll have less chance of getting errors.

arijeet
  • 1,858
  • 18
  • 26