[英]i want to execute this code and output in default output format using php?
<?php
$field_format = array('format'=>"date('Y-m-d',strtotime(created_date))");//array define here
echo 'default output '.date('Y-m-d',strtotime('26-09-2016'));
echo nl2br('<br/>');
echo nl2br('<br/>');
if (array_key_exists('format', $field_format)) {
$value_in_format = $field_format['format'];
$value_in_format = preg_replace('/created_date/','26-09-2016', $value_in_format);
// printed var_dump format // 打印 var_dump 格式
var_dump(preg_replace('/created_date/','26-09-2016', $value_in_format));
echo nl2br('<br/>');
echo nl2br('<br/>');
echo $value_in_format;
// i want this output should be same as default output // 我希望这个输出应该与默认输出相同
echo nl2br('<br/>');
echo nl2br('<br/>');
}
?>
I'm not sure what do you want to do, but your output is in another format because of the preg_replace..If you change your preg_replace with this line:我不确定你想做什么,但你的输出是另一种格式,因为 preg_replace ..如果你用这一行改变你的 preg_replace:
$value_in_format = preg_replace('/created_date/','2016-09-26', $value_in_format);
then your default output will be the same with the "$value_in_format" output.那么您的默认输出将与“$value_in_format”输出相同。
Update:更新:
<?php
$field_format = array('format'=>"date('Y-m-d',strtotime(created_date))");//array define here
echo 'default output '.date('Y-m-d',strtotime('26-09-2016'));
echo nl2br('<br/>');
echo nl2br('<br/>');
if (array_key_exists('format', $field_format)) {
$value_in_format = $field_format['format'];
$value_in_format = preg_replace('/created_date/','"26-09-2016"', $value_in_format);
//var_dump(preg_replace('/created_date/','\"26-09-2016\"', $value_in_format));
echo nl2br('<br/>');
echo nl2br('<br/>');
eval("echo $value_in_format;");
echo nl2br('<br/>');
echo nl2br('<br/>');
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.