The most recent source file in the project that needs to output the browser needs to be stripped of the comments in HTML. Read a lot of programs on the Internet, but many of the answers are the same, and can not solve my problem, so I wrote the regular expression, but also have a more profound understanding.
The first is to compare the basics:
$a = ' <!--Ceshi-->ceshi ';
$a = preg_replace (' #<!--. *--># ', ', $a);
Var_dump ($a);
The code above will output Ceshi.
But if it's the string below, it's not going to work the way we want it to.
$a = ' <!--ceshi-->ceshi<!--ceshi--> ';
$a = preg_replace (' #<!--. *--># ', ', $a);
Var_dump ($a);
So we'll change the matching rules to the following format
But in HTML if there is <!--[if Lt IE 9]>ceshi<! [endif]--> Such code can not be removed, so we need to improve the matching rules, change to the following format
And then if there's a <script><!--ceshi//--></script> code in HTML, we need to change our matching rules to the following format
In that case, I basically removed the comments I needed to get rid of the HTML!
The above is a small series for everyone to bring PHP use regular expressions to remove the annotation method in HTML all content, I hope that we support cloud Habitat Community ~