Discussion and association of PHP closing tag

  • 2020-05-30 19:44:41
  • OfStack

When PHP parses a file, the search begins < ? php and end tag? > , the tag tells PHP to start and stop interpreting the code. This parsing allows PHP to be embedded in a variety of documents, and anything outside the 1 pair of start and end tags is ignored by the PHP parser. Most of the time PHP is embedded in HTML documents.

Single-line comments only comment to the end of the line or the current PHP code block, depending on which appears first. This means that in //... ? > Or #... ? > The HTML code will then be displayed:? > Jumping out of PHP mode and returning to HTML mode, // or # does not affect this 1 point.

As can be seen from the above discussion, even? > The PHP parser also thinks that PHP parsing ends when it appears in the // comments (when PHP encounters the end tag? > , simply output what follows as it is (unless it is followed by a new line, see the command separator) until it hits the next start tag.
//$a = '<a href="test.html" title="#">test</a><a href="test.html" title="#">test</a>'; 
//preg_match_all('|<a[^>]+href="([^\"]*)".*?>|', $a, $b); 

The output is:
:!php preg.php 
|', $a, $b); 

How to fix the above problems? Or do you use /* */ for comments, or do you use? > Connect with a string concatenator, as follows:
$a = '<a href="test.html" title="#">test</a><a href="test.html" title="#">test</a>'; 
preg_match_all('|<a[^>]+href="([^\"]*)".*?'.'>|', $a, $b); 

This 1 detail also applies to the JS closing tag < /script >

Related articles: