2016-09-26 70 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 –