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). Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.