Home > Backend Development > PHP Problem > What is the usage of php eval

What is the usage of php eval

藏色散人
Release: 2023-03-14 06:30:02
Original
4110 people have browsed it

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

What is the usage of php eval

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

php eval用法是什么?

PHP eval() 函数

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

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

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

语法

eval(phpcode)
Copy after login

参数

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

提示和注释

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

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

例子

<?php
$string = "beautiful";
$time = "winter";
$str = &#39;This is a $string $time morning!&#39;;
echo $str. "<br />";
eval("\$str = \"$str\";");
echo $str;
?>
Copy after login

输出:

This is a $string $time morning!
This is a beautiful winter morning!
Copy after login

推荐学习:《PHP视频教程

The above is the detailed content of What is the usage of php eval. For more information, please follow other related articles on the PHP Chinese website!

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