0

I have an url which looks like page.php?stuff=stuff&stuff=stuff&order=sometext&page=number

and I want to remove the "order=sometext" part. I'm using this php code :

        $link = $_SERVER['REQUEST_URI'];
        $re = "/&order=/";
        $link = preg_replace($re, "", $link);

And I'm looking for the correct pattern that should be $re to clear the "order=sometext" from the url. The "&page=number" part has to be kept when present, but isn't always there. Any ideas ?

Thanks in advance !

Kishlin
  • 373
  • 2
  • 15

2 Answers2

0

The regex should be

(&|\?)order=[^&]+

(&|\?): the order could be first in the list, so we are removing either & or ?.

nicael
  • 18,550
  • 13
  • 57
  • 90
0

Actually I made it work using /&order=[^&]*/. :)

chris85
  • 23,846
  • 7
  • 34
  • 51
Kishlin
  • 373
  • 2
  • 15