Reputation: 4515
I'm wish to remove all content in a string after this phrase in PHP:
On 17 Mar 2015
How would I match any date?
EDIT: I use this currently to remove the phrase and all content after it in a string:
if (strpos($body,"On 17 Mar 2015") !== false) { $body = substr($body, 0, strpos($body, "On 17 Mar 2015"));}
Input =
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
Expected output:
reply reply reply reply reply reply reply reply
for any possible date
Upvotes: 0
Views: 70
Reputation: 810
If the format of the phrase doesn't change, the regular expression below should do the trick for any date possible.
$phrase = "On 17 Mar 2015";
preg_match("#(?<=On\s)\d+\s\w+\s\d+#", $phrase, $matches);
echo $matches[0];
Upvotes: 1