Home >Backend Development >PHP Tutorial >Discussion and association on the use of PHP end tags_PHP tutorial

Discussion and association on the use of PHP end tags_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:13:141226browse

When PHP parses a file, it looks for the opening , which 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 opening and closing 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 to the current block of PHP code, 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 # has no effect at this point.

It can be seen from the above discussion that even if ?> appears in the // comment, the PHP parser will consider that PHP parsing is over (when PHP encounters the end mark?>, it will simply follow it The contents of are output as is (unless immediately followed by a new line, see command separator) until the next start tag is encountered).

Copy code The code is as follows:

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

The output is:
Copy the code The code is as follows:

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

How to fix the above problem? Or you use /* */ to comment, or use ?> Use string concatenation characters to connect, as follows:
Copy code The code is as follows:

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

This detail also applies to JS closing tag

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326549.htmlTechArticleWhen PHP parses a file, it looks for start ?php and end tags?, which tell PHP to start and stop interpretation. code in it. This method of parsing allows PHP to be embedded into various documents...
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