營造您的網路城市,開創您的無限商機

Networt city

create your infinite

business opportunities

DfD 網頁設計工作室::DfD web design studio

~實現您的網路夢想


eval

最近寫PHP 程式時,突然想說如果程式碼是可變的話,也就是利用程式控制程式碼那就非常便利了,於是上網查了一下,發現了 eval 這個有趣的指令。

eval

(PHP 4, PHP 5) eval — Evaluate a string as PHP code Description mixed eval ( string $code_str )

example

<?php
$string 
'cup';
$name 'coffee';
$str 'This is a $string with my $name in it.';
echo 
$str"\n";
eval(
"\$str = \"$str\";");
echo 
$str"\n";
?>

The above example will output:

This is a $string with my $name in it.

This is a cup with my coffee in it.

也就是eval 可以把字串當指令執行,這樣就可以利用eval 來執行程式碼編寫程式碼,十分的有用,連javascript 也有支援 eval

資料參考: php manual