Jump to content

simple_html_dom.php help


bschultz
Go to solution Solved by 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

  • Solution

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

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.