bschultz Posted August 15, 2017 Share Posted August 15, 2017 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! Quote Link to comment Share on other sites More sharing options...
Solution bschultz Posted August 15, 2017 Author Solution Share Posted August 15, 2017 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>"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.