我写了一个php脚本,我希望该脚本能够执行,然后执行的结果将被保存到另一个文件,然后它将重定向到该保存文件。
现在我的问题是我执行的脚本有一些我需要保存的PHP代码,因为它在保存的文件中
<?php
function ago($time)
{
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$difference = $now - $time;
$tense = "ago";
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1) {
$periods[$j].= "s";
}
return "$difference $periods[$j] 'ago' ";
}
?>
我试图从执行脚本中回显这些行,以便可以保存上面的行。 我就是这样做的。
<?php
function rowFromVar($last_modified) {
$result = " <?php $$last_modified = filemtime(__FILE__);
function ago($time)
{
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$difference = $now - $time;
$tense = "ago";
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1) {
$periods[$j].= "s";
}
return "$difference $periods[$j] 'ago' ";
}
$last=ago($last_modified);";
return $result;
}
print rowFromVar("last_modified");
但我有一些错误,比如
( ! ) Parse error: syntax error, unexpected T_STRING in C:\wamp\www\SEO stat[Repica OF server]\Tools\domain_lookup1.php on line 109
任何帮助将不胜感激。
答案 0 :(得分:0)
<?php
function rowFromVar($last_modified) {
$result = <<<XXX_DELIMETER_XXX
<?php \$last_modified = filemtime(__FILE__);
function ago(\$time)
{
\$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
\$lengths = array("60","60","24","7","4.35","12","10");
\$now = time();
\$difference = \$now - \$time;
\$tense = "ago";
for(\$j = 0; \$difference >= \$lengths[\$j] && \$j < count(\$lengths)-1; \$j++) {
\$difference /= \$lengths[\$j];
}
\$difference = round(\$difference);
if(\$difference != 1) {
\$periods[\$j].= "s";
}
XXX_DELIMETER_XXX;
return "$difference $periods[$j] 'ago' ";
}
$last=ago($last_modified);";
return $result;
}
print rowFromVar("last_modified");
它应该有效,你正在使用未转义的双引号..
如果有帮助请使用+1按钮