PHP include任意文件或URL介绍_php实例

WBOY
Release: 2016-06-07 17:20:19
Original
701 people have browsed it

实践出真理,写一个简单文件PHP文件include一个js文件,执行后没有报错或警告信息,同时看到被包含js的文件的内容被打印出来。因此得出结论:include 目标文件可以是任意类型。

现在再回头看include的官方文档,其中有这么一段话:“当一个文件被包含时,语法解析器在目标文件的开头脱离 PHP 模式并进入 HTML 模式,到文件结尾处恢复。由于此原因,目标文件中需要作为 PHP 代码执行的任何代码都必须被包括在有效的 PHP 起始和结束标记之中。” 注意其中提到“HTML模式,PHP代码必须包括在有效的PHP标记符中”,仔细体会其含义,它其实隐式的说明了include可以是任意类型的文件。

另外在4.3.0以后,include 目标文件还可以是一个url,当然前提是需要在配置中设置 allow_url_include 为 on。

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!