php eval用法是什么
2022-12-02 09:01:16
267
{{single.collect_count}}

php eval函数的作用是把字符串按照PHP代码来计算,其使用语法如“eval(phpcode)”,其中参数phpcode则是规定要计算的PHP代码。

php入门到就业线上直播课:进入学习
Apipost = Postman + Swagger + Mock + Jmeter 超好用的API调试工具:点击使用

本文操作环境:Windows7系统、PHP7.1、Dell G3电脑。

php eval用法是什么?

PHP eval() 函数

eval() 函数把字符串按照 PHP 代码来计算。

该字符串必须是合法的 PHP 代码,且必须以分号结尾。

如果没有在代码字符串中调用 return 语句,则返回 NULL。如果代码中存在解析错误,则 eval() 函数返回 false。

语法

eval(phpcode)
登录后复制

参数

phpcode必需。规定要计算的 PHP 代码。

提示和注释

注释:返回语句会立即终止对字符串的计算。

注释:该函数对于在数据库文本字段中供日后计算而进行的代码存储很有用。

例子

<?php$string = "beautiful";$time = "winter";$str = 'This is a $string $time morning!';echo $str. "<br />";eval("\$str = \"$str\";");echo $str;?>
登录后复制

输出:

This is a $string $time morning!This is a beautiful winter morning!
登录后复制

推荐学习:《PHP视频教程

以上就是php eval用法是什么的详细内容,更多请关注php中文网其它相关文章!

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}