我希望在PHP中删除此短语后的字符串中的所有内容:
On 17 Mar 2015
我如何匹配任何日期?
编辑:我目前使用它来删除短语及其后面的所有内容:
if (strpos($body,"On 17 Mar 2015") !== false) { $body = substr($body, 0, strpos($body, "On 17 Mar 2015"));}
输入=
reply reply reply reply reply reply reply reply
On 17 Mar 2015, at 10:23, user wrote:
> email email email email email email email email email email email email
> email email email email email email email email email email email email
预期产出:
reply reply reply reply reply reply reply reply
任何可能的日期
答案 0 :(得分:1)
如果短语的格式没有改变,下面的正则表达式应该可以在任何可能的日期进行。
$phrase = "On 17 Mar 2015";
preg_match("#(?<=On\s)\d+\s\w+\s\d+#", $phrase, $matches);
echo $matches[0];