Jump to content

simple_html_dom.php help


bschultz

Recommended Posts

I have an application where a user copies and pastes into a form textbox some information from another site (which I don't control).  This info is ALWAYS in html table form...but is horribly mangled with css and other info that the application doesn’t need.

 

So, I thought to run the pasted data through simple_html_dom to get me just the contents of the table...and put it into a new table that's free of other formatting and such.

 

Here's the code...

 

 

$html = str_get_html($_POST['stats']);
$html->find("table");
foreach($html->find('tr') as $row)

{  // start foreach table row
echo "<tr>";
   foreach ($row->find('td')->plaintext as $content)
{
echo "<td>$content</td>";
}
echo "</tr>";
}

If I echo the contents of $_POST['stats'], I get the full css'd table.  Running through the 2 foreach statements...I get nothing echoed.

Any ideas where I've gone wrong?

Thanks!
Link to comment
Share on other sites

I got it...

 

 

echo "<table border= '1'>";

$html = str_get_html($_POST['stats']);

$html->find("table");

 foreach($html->find('tr') as $row)
 {
 echo "<tr>";
          foreach ($row->find('td') as $content)
          {
          echo "<td>"; echo $content->plaintext;  echo "</td>";
          }
 echo "</tr>";
 }

echo "</table>";
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.