0

My string is

"http://exanmple.com/katalogas/?is_search=1&type=list&filter=search_1&activity=&activity_id=&activity=langai&activity_id=&region_id=-2&page_no=2"

I want replace from string all page_no=2 number can change, phrase is static page_no

What I try:

/\&page_no=[0-9]\b/i
2
  • Remove from string - replace with empty spaces Commented Jul 25, 2015 at 10:13
  • So check the following answer! Commented Jul 25, 2015 at 10:15

1 Answer 1

1

You can match this regex:

/(?<=\?)page_no=\d+&|&page_no=\d+\b/i

Code:

$url = preg_replace('/(?<=\?)page_no=\d+&|&page_no=\d+\b/i', '', $url);

RegEx Demo

Sign up to request clarification or add additional context in comments.

2 Comments

You should add an optional & at the end of the pattern to avoid && or ?& when page_no isn't the last parameter.
Thanks, yes I realized that a & also need to be removed, edited now.

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.