我想隨機顯示一個PHP碼等爲我有包括回波內PHP代碼從隨機文本
<?php
// load the file that contain thecode
$adfile = "code.txt";
$ads = array();
// one line per code
$fh = fopen($adfile, "r");
while(!feof($fh)) {
$line = fgets($fh, 10240);
$line = trim($line);
if($line != "") {
$ads[] = $line;
}
}
// randomly pick an code
$num = count($ads);
$idx = rand(0, $num-1);
echo $ads[$idx];
?>
的code.txt具有類似於
線<?php print insert_proplayer(array("width" => "600", "height" => "400"), "http://www.youtube.com/watch?v=xnPCpCVepCg"); ?>
Proplayer是一個顯示視頻的wordpress插件。 code.txt中的代碼運行良好,但是當我使用code.txt中的選擇行時不行。我得到的不是完整的php行:
"width" => "600", "height" => "400"), "http://www.youtube.com/watch?v=xnPCpCVepCg"); ?>
我該如何讓echo顯示php代碼,而不是php代碼的txt版本?
把打印語句放在一個php文件中,而不是txt? – 2011-02-17 23:00:37
這整個方法看起來不對,code.txt是如何生成的? – 2011-02-17 23:00:40