简体   繁体   English

在php中提取正则表达式

[英]Extract Regular expression in php

As I can do to remove this type of dates from a string in PHP 我可以从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 我只想提取以下内容: 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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