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

Analysis: Usage details of PHP end tag

WBOY
Release: 2016-07-25 08:56:56
Original
1045 people have browsed it
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); 
Copy after login

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); 
Copy after login

Instructions: This detail also applies to JS closing tags .



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template