Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php regular expression to filter data

Tags:

regex

php

i am just getting stuck with php regular expression to filter data. I want to detect 'Results 1 - 20 of 60' using regular expression and then delete the data from $content

$content="We have Results 1 - 20 of 60 some blah blah blah";
$content = preg_replace("/regular-expression/", " ", $content);

Here expected output is: We have some blah blah blah
Any Idea?

like image 588
Jessica Lingmn Avatar asked Jun 03 '26 09:06

Jessica Lingmn


1 Answers

Shortly, here is a solution

$content="We have Results 1 - 20 of 60 some blah blah blah";
$content = preg_replace("/(Results)(\\s+)(\\d+)(\\s+)(-)(\\s+)(\\d+)(\\s+)(of)(\\s+)(\\d+)/", " ", $content);
like image 175
Prijm.com Avatar answered Jun 06 '26 06:06

Prijm.com