jdoe jdoe - 2 years ago 231
PHP Question

how to convert date format in a textarea php mysql

I want to change the date format in a text area,

<textarea tabindex="0"
class="input_lkl "
name=""><?php echo $class['new']['ord_added_usr']; ?></textarea>

and it show me the date format like this

[120] Added by [admin] on [2016-05-18]

and I want to change the format into Y-m-d to d-m-Y

[120] Added by [admin] on [18-05-2016]

Answer Source

Assuming $class['new']['ord_added_usr'] holds [120] Added by [admin] on [2016-05-18]

You can use preg_replace_callback

echo preg_replace_callback("/(\d{4}-\d{2}-\d{2})/", function($matches){
    return date("d-m-Y",strtotime($matches[0]));


[120] Added by [admin] on [18-05-2016]


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download