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! Link to comment Share on other sites More sharing options...
bschultz Posted August 15, 2017 Author 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>"; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.