简体   繁体   中英

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

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
)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM