When PHP parses a file, it looks for the start <?php and end tag, and the tag tells PHP to start and stop interpreting the code. The parsing of this approach allows PHP to be embedded in a variety of documents, which are ignored by the PHP parser for everything except a pair of start and end tags. In most cases, PHP is embedded in an HTML document.
A single-line comment is only commented to the end of the line or the current block of PHP code, depending on which first appears. This means in//...? > or # ...? The HTML code after > will be displayed:?> out of PHP mode and returns HTML mode,//or #并不能影响到这一点.
As can be seen from the above discussion, even if?> appears in the//comment, the PHP parser will also think that PHP parsing is over (when PHP encounters the end tag?>, it simply outputs the following content (unless followed by a new line, see instruction Separator) until the next start tag is encountered.
Copy Code code as follows:
<?php
$a = ' <a href= ' test.html "title=" # ">test</a><a href=" test.html "title=" # ">test</a>";
Preg_match_all (' |<a[^>]+href= "([^\"]*) ". *?>| ', $a, $b);
Print_r ($b);
The output is:
Copy Code code as follows:
:!php preg.php
| ', $a, $b);
Print_r ($b);
How can we rectify the above problems? or you use/*/* to annotate, or to connect?> with a string connector, as follows:
Copy Code code as follows:
<?php
$a = ' <a href= ' test.html "title=" # ">test</a><a href=" test.html "title=" # ">test</a>";
Preg_match_all (' |<a[^>]+href= "([^\"]*) ". *? '. ' >| ', $a, $b);
Print_r ($b);
This detail also applies to JS end tags </script>