johnsmith153 Posted June 16, 2012 Share Posted June 16, 2012 I have scraped some data from a website and have the HTML. I just need to now remove a table from that HTML, so I'm guessing I need to search in the HTML for a start and end <table> tag. If there is more than one table, then I want to remove all of them. Can someone point me in the right direction? Also, removing images would be great (anything with <img). Link to comment https://forums.phpfreaks.com/topic/264284-strip-table-from-html-scrape/ Share on other sites More sharing options...
Adam Posted June 16, 2012 Share Posted June 16, 2012 You can use a regular expression: $html = preg_replace('/<table[^>]*>.*?<\/table>/s', '', $html); That will match any opening table tag with or without attributes, up until the first found closing table tag, and then replace it all with nothing. Also preg_replace() will replace all occurences unless you tell it not to, using the 4th parameter. Link to comment https://forums.phpfreaks.com/topic/264284-strip-table-from-html-scrape/#findComment-1354374 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.