I know how to get the html source code via cUrl, but I want to remove the comments on the html document (I mean what is between <!-- .. -->
). In addition, if I can take just the BODY
of the html document. thank you.
To create hidden comments in HTML, add <! --- tag and end it with -- >. Whatever comes inside it is hidden. These comments are beneficial for those who need to refer the code again, which allow them to easily understand the code.
CSS comments are eliminated with the rewrite_css filter, and Javascript comments are eliminated with the rewrite_javascript filter. The filter reduces the transfer size of HTML files by removing most HTML comments.
An HTML comment begins with <! –– and the comment closes with ––> . HTML comments are visible to anyone that views the page source code, but are not rendered when the HTML document is rendered by a browser.
Once installed, remove comments in your code by opening the command palette ( Ctrl + Shift + P ), entering "Remove all comments" and pressing enter. Voilà , all the comments are gone 🎉 !
Regex solved this problem for me as follows:
function remove_html_comments($html = '') {
return preg_replace('/<!--(.|\s)*?-->/', '', $html);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With