Marcos Trentacoste
Marcos Trentacoste

Reputation: 33

Extract Regular expression in php

As I can do to remove this type of dates from a string in PHP

En progreso Sin resolver 14/jul/16 17/jul/16 19/jul/16 12:00 PM 12 h Acciones

I want to extract only this: 19/jul/16 12:00 PM

Upvotes: 1

Views: 56

Answers (2)

fmoradi
fmoradi

Reputation: 91

try this :

$pattern = '#\d{1,2}/\w+/\d{1,2}\s\d{1,2}:\d{1,2}\s[AP]M#';
$string = ' df progreso sin resolver 14/jul/16 17/jul/16 19/jul/16 12:00 PM 12 h   Acciones';

preg_match($pattern , $string , $matches);
print_r($matches);

result will be :

Array
(
    [0] => 19/jul/16 12:00 PM
)

Upvotes: 3

Indrasis Datta
Indrasis Datta

Reputation: 8618

If this is a static string, this code will work for you:

$string = "En progreso Sin resolver 14/jul/16 17/jul/16 19/jul/16 12:00 PM 12 h Acciones";
$array  = explode(' ', $string);
echo implode(' ',[$array[6], $array[7], $array[8]]);  

Output:

19/jul/16 12:00 PM

Upvotes: -1

Related Questions