簡體   English   中英

我想使用php以默認輸出格式執行此代碼並輸出?

[英]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);

// 打印 var_dump 格式

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

我不確定你想做什么,但你的輸出是另一種格式,因為 preg_replace ..如果你用這一行改變你的 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/>');
}
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM