Skip to content

How to Remove HTML Comments with PHP?

Last updated on September 17, 2014

In my recent project there are lot of HTML comments for each block. I don’t want to show the comments when viewing the source code because there is no reason to show.

I found this <!–(.|s)*?–> little regular expression that neatly did the trick.

Here is a quick simple function ,that can be remove the HTML Comments from the given content.

function removeHtmlComments($content = '') {
	return preg_replace('//', '', $content);
}
0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments