3

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?

2
  • What have you tried? See ask advice, please. Commented Mar 18, 2013 at 16:08
  • It looks like you are trying to solve the wrong problem. What are you trying to accomplish Commented Mar 18, 2013 at 16:14

3 Answers 3

3

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);
Sign up to request clarification or add additional context in comments.

Comments

0

You can use this regex

 $content = preg_replace("/\s*results\s+\d+\s+-\s+\d+\s+of\s+\d+\s*/i", " ", $content);

to remove Results 1 - 20 of 60.

Comments

0

You can do this via

<?php
    $str="We have Results 1 - 20 of 60 some blah blah blah";
    echo preg_replace("/(Results)(\\s+)(\\d+)(\\s+)(-)(\\s+)(\\d+)(\\s+)(of)(\\s+)(\\d+)/", " ", $str);
?>

Output

We have some blah blah blah

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.