About the use of PHP end tag details of the discussion and Lenovo _php skills

Source: Internet
Author: User
Tags lenovo
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.