2016-09-26 99 views
-2
<?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格式我想执行此代码并使用PHP默认输出格式输出?

var_dump(preg_replace('/created_date/','26-09-2016', $value_in_format)); 
    echo nl2br('<br/>'); 
    echo nl2br('<br/>'); 
    echo $value_in_format; 

//我想这个输出应该是一样的默认输出

echo nl2br('<br/>'); 
    echo nl2br('<br/>'); 
} 
?> 

回答

0

我不知道是什么你想要做什么,但你的输出是另一种格式,因为preg_replace ..我F你这一行改变你的preg_replace:

$value_in_format = preg_replace('/created_date/','2016-09-26', $value_in_format); 

那么你的默认输出将与“$ value_in_format”输出相同。

更新:

<?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/>'); 
} 
?> 
+0

我想运行PHP的日期函数来得到的preg_replace第二个参数值。但它显示为字符串格式,如date('Ym-d',strtotime(26-09-2016)) –

+0

它以字符串格式显示,因为在数组中定义错误:this:array('format'=>“date ( 'YM-d',的strtotime(CREATED_DATE))“);应该是:array('format'=> date('Y-m-d',strtotime(“Ymd”))); – mihutz

+0

但我想从preg_replace –