Rick Joe Rick Joe - 5 months ago 25
PHP Question

Get date in a string php

I want to get a date in a string in php and convert this date to other format:

eg: today is 02/03/2016

$string = preg_replace('~(\d{2})/(\d{2})/(\d{2,4})~', '', $string);

but it is only erasing the date. it will print:

today is

after get the date I want to change to other format:

$date = new DateTime($string);
$result = $date->format('F d, Y');

but, how to get only the date in the string? without erase it?

$string = 'today is 02/03/2016';
$string = preg_match('/\d{2}\/\d{2}\/\d{4}/', $string, $date);
$date = new DateTime($date[0]);
$result = $date->format('F d, Y');