Heim  >  Artikel  >  Backend-Entwicklung  >  Was ist die Verwendung von PHP Eval?

Was ist die Verwendung von PHP Eval?

藏色散人
藏色散人Original
2021-11-24 10:12:184029Durchsuche

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

Was ist die Verwendung von PHP Eval?

本文操作环境: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 = &#39;This is a $string $time morning!&#39;;
echo $str. "<br />";
eval("\$str = \"$str\";");
echo $str;
?>

输出:

This is a $string $time morning!
This is a beautiful winter morning!

推荐学习:《PHP视频教程

Das obige ist der detaillierte Inhalt vonWas ist die Verwendung von PHP Eval?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn