Get the App
SLTechnology News&Howtos  ›  Development  › 

How to remove html comments from php

Shulou Source: shulou.com Published: 2022-06-03 10:41:51 11月14日 Update

In this issue, the editor will bring you about how to remove html comments from php. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Php to remove html comments: 1, open the corresponding PHP code file; 2, view the format of html comments; 3, through the "preg_replace (" / ",", $html); "method to remove html comments.

This article operating environment: windows7 system, PHP7.1 version, Dell G3 computer.

How does php remove html comments?

PHP filter html comments

Filter html comments:

The so-called filtering is nothing more than string matching and substitution. The regular matching substitution function preg_replace (reg,replace,string); PHPer is clear that the key to this function lies in the accuracy of reg, so let's give it a try:

The first thing to know is the format of html comments, which goes like this:.

Start regular writing

$html = "something"; $html = preg_replace ("/ /", "", $html); echo $html

The above code will output something. It seems to be a success. Don't worry, just test a few more examples.

$html = "something"; $html = preg_replace ("/ /", "", $html); echo $html

This example tells us that writing in this way does not achieve the desired effect, so the rule is optimized like this.

Preg_replace ("/", "", $html)

Well, that's satisfactory, but there's code like this in html, which is browser-compatible code that obviously can't be filtered, so our rule continues to optimize and look like this.

Preg_replace ("/", "", $html)

And then if there's code in html, we need to change our matching rules again, like this.

Preg_replace ("/", "", $html)

In that case, I basically get rid of the html comments I need to remove!

Windfall: in the optimization process, there are no many lines of comments to consider, but the rules unexpectedly match multiple lines of comments, I do not know if it is because of the html read from the file!

After testing, it has not been found that the text will be filtered out. If you have any questions, please leave a message for correction.

The above is the editor for you to share the php how to remove the html comments, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Comments code regularity accidents examples content functions files methods formats rules analysis testing clarity precision success in this case professional small and medium-sized key Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno Huawei macOS Shulou Tech Info