eval
把字符串作為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 代碼。 |