gpt4 book ai didi

php - 停止 php 处理文件

转载 作者:可可西里 更新时间:2023-11-01 12:46:37 26 4
gpt4 key购买 nike

有没有办法让 php 停止处理一个文件,让它只处理它已经解析的部分。我的意思是这样的:

<some data here>
<?php phpinfo(); [IS THERE ANY THING I CAN PUT HERE] ?>
<more data>
[IS THERE ANY THING I CAN PUT HERE]
<?HOW CAN I MAKE PHP NOT PARSE THIS?>

有没有办法让 php 在第一个 php 部分之后忽略数据?

最佳答案

另一种解决方案可能是使用 __halt_compiler :

Halts the execution of the compiler. This can be useful to embed data in PHP scripts, like the installation files.

Byte position of the data start can be determined by the __COMPILER_HALT_OFFSET__ constant which is defined only if there is a __halt_compiler() presented in the file.

典型用法是 Phar archives ,当您需要将 PHP 和(可能是二进制的)数据嵌入到单个文件中,并且 PHP 代码需要访问该数据时。


实际上是有区别的:这段代码:

blah blah
<?php phpinfo(); ?>
glop glop
<?php exit(); ?>
<?HOW CAN I MAKE PHP NOT PARSE THIS?>

给我一​​个 Parse error: syntax error, unexpected T_STRING
(我想可能是因为我启用了 short_open_tag)


而这一个:

blah blah
<?php phpinfo(); ?>
glop glop
<?php __halt_compiler(); ?>
<?HOW CAN I MAKE PHP NOT PARSE THIS?>

工作正常——这个无效的 PHP 代码在调用 __halt_compiler() 之后。

关于php - 停止 php 处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1823635/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com