位置: 编程技术 - 正文

PHP:eval()的用法_misc函数(php foreach())

编辑:rootadmin
eval

推荐整理分享PHP:eval()的用法_misc函数(php foreach()),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:php eval,phpforeach用法,php foreach(),php eval()函数的作用是什么?,php eval函数漏洞利用,php validate()函数,php eval()函数的作用是什么?,php eval函数漏洞利用,内容如对您有帮助,希望把文章链接给更多的朋友!

(PHP 4, PHP 5)

eval — 把字符串作为PHP代码执行

说明 mixed eval ( string $code )

把字符串 code 作为PHP代码执行。

Caution

The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.

参数

code

需要被执行的字符串

代码不能包含打开/关闭 PHP tags。比如,&#;echo "Hi!";&#; must be passed instead of &#;<? echo "Hi!"; >&#;. It is still possible to leave and reenter PHP mode though using the appropriate PHP tags, e.g. &#;echo "In PHP mode!"; ?>In HTML mode!<? echo "Back in PHP mode!";&#;.

Apart from that the passed code must be valid PHP. This includes that all statements must be properly terminated using a semicolon. &#;echo "Hi!"&#; for example will cause a parse error, whereas &#;echo "Hi!";&#; will work.

return 语句会立即中止当前字符串的执行。

PHP:eval()的用法_misc函数(php foreach())

The code will be executed in the scope of the code calling eval(). Thus any variables defined or changed in the eval() call will remain visible after it terminates.

返回值

eval() 返回 NULL,除非在执行的代码中 return 了一个值,函数返回传递给 return 的值。 如果在执行的代码中有一个解析错误,eval() 返回 FALSE,之后的代码将正常执行。无法使用 set_error_handler() 捕获 eval() 中的解析错误。

范例

Example #1 eval() 例子 - 简单的文本合并

<?php$string='cup';$name='coffee';$str='Thisisa$stringwithmy$nameinit.';echo$str."n";eval("$str="$str";");echo$str."n";?>

以上例程会输出:

注释

Note: 因为是一个语言构造器而不是一个函数,不能被可变函数 调用。

Tip

和直接将结果输出到浏览器一样,可使用输出控制函数来捕获当前函数的输出,然后(例如)保存到一个 string 中。

Note:

如果在执行的代码中产生了一个致命的错误(fatal error),整个脚本会退出。

参见

call_user_func() - 把第一个参数作为回调函数调用

PHP:ignore_user_abort()的用法_misc函数 ignore_user_abort(PHP4,PHP5)ignore_user_abort设置客户端断开连接时是否中断脚本的执行说明intignore_user_abort([string$value])设置客户端断开连接时是否中断脚本的执

PHP:exit()的用法_misc函数 exit(PHP4,PHP5)exit输出一个消息并且退出当前脚本说明voidexit([string$status])voidexit(int$status)中止脚本的执行。尽管调用了exit(),Shutdown函数以及objectdestructors总

PHP:__halt_compiler()的用法_misc函数 __halt_compiler(PHP5=5.1.0)__halt_compiler中断编译器的执行说明void__halt_compiler(void)中断编译器的执行。常用于在PHP脚本内嵌入数据,类似于安装文件。可以通过

本文链接地址:https://www.jiuchutong.com/biancheng/280634.html 转载请保留说明!

上一篇:PHP:highlight_file()的用法_misc函数

下一篇:PHP:ignore_user_abort()的用法_misc函数

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络