search
Homephp教程php手册关于PHP结束标签?>的使用细节

关于PHP结束标签?>的使用细节

Jun 13, 2016 am 10:54 AM
ampphpuseaboutandLook forstartdocumenthourLabelofdetailFinishparse

当PHP解析一个文件时,会寻找开始,标记告诉PHP开始和停止解释其中的代码。此种方式的解析可以使PHP嵌入到各种不同的文档中,凡是在一对开始和结束标记之外的内容都会被PHP解析器忽略。大多数情况下PHP都是嵌入在HTML文档中的。

 

单行注释仅仅注释到行末或者当前的 PHP 代码块,视乎哪个首先出现。这意味着在 // ... ?> 或者 # ... ?>之后的 HTML 代码将被显示出来:?> 跳出了 PHP 模式并返回了 HTML 模式,// 或 #并不能影响到这一点。

 

由以上讨论可可知,即使?>出现在//注释中,PHP解析器也会认为PHP解析结束(当 PHP 碰到结束标记 ?> 时,就简单地将其后的内容原样输出( 除非其后紧接着一个新行,参见指令分隔符)直到碰到下一个开始标记为止)。

 

 

//$a = 'testtest';

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

//print_r($b);

输出为:

 

:!php preg.php

|', $a, $b);

//print_r($b);www.2cto.com

如何修正上述问题呢?或者你使用/* */进行注释,或者将?>用字符串连接符进行连接,如下:

 

 

$a = 'testtest';

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

print_r($b);

这一细节同样适用于JS结束标签

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function