Home  >  Article  >  Backend Development  >  Analysis: Usage details of PHP end tag

Analysis: Usage details of PHP end tag

WBOY
WBOYOriginal
2016-07-25 08:56:561011browse
This article deeply discusses the usage of end tags in PHP and related details. Friends in need can refer to it.

We know that when PHP parses a file, it will look for the beginning ?php and the end tag?. These tags tell PHP to start and stop interpreting the code within it.

This method of parsing allows PHP to be embedded in various documents. Any content outside a pair of start and end tags will be ignored by the PHP parser.

In most cases PHP is embedded in HTML documents.

Single-line comments only comment to the end of the line or the current PHP code block, whichever comes first. This means that the HTML code after // ... ?> or # ... ?> will be displayed: ?> jumps out of PHP mode and returns to HTML mode, // or # does not affect this.

Even if ?> appears in // comments, the PHP parser will consider that PHP parsing is ended (when PHP encounters the end mark ?>, the content after it will be output as is (unless it is followed by a new line, see instructions delimiter) until the next start tag is encountered).

Example:

<?php 
//$a = 'testtest'; 
//preg_match_all('|]+href="([^\"]*)".*?>|', $a, $b); 
//print_r($b); 

Output result:

:!php preg.php |', $a, $b); //print_r($b);

You can use /* */ to comment, or connect ?> with string concatenation to correct the above problem, for example:

<?php 
$a = 'testtest'; 
preg_match_all('|]+href="([^\"]*)".*?'.'>|', $a, $b); 
print_r($b); 

Instructions: This detail also applies to JS closing tags .



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn