當前位置: 首頁> 函數類別大全> eval

eval

把字符串作為PHP代碼執行
名稱:eval
分類:雜項
所屬語言:php
一句話介紹:把字符串按照PHP 代碼來計算。

定義和用法

eval()函數將字符串作為PHP 代碼來執行。

該字符串必須是有效的PHP 代碼,並且必須以分號結尾。

注意:如果字符串中包含return 語句,它將會立即終止對字符串的求值。

提示:這個函數在將PHP 代碼存儲在數據庫中時可能會很有用。

實例

將字符串作為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!

文法

eval ( phpcode )
參數 描述
phpcode 必需。規定要計算的PHP 代碼。
同類函數
熱門文章