0

I have this code:

$url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url = preg_replace("page=[\d]+","",$url);

I have a link like this: http://localhost/search?q=WORD+FOR+SEARCH&page=4

I'm trying to get that URL then to remove &page=. I never worked with regex for patterns. That's my code. Can someone help me ? Thank you !

This is the error I get when I try to execute that code:

preg_replace(): Delimiter must not be alphanumeric or backslash

chris85
  • 23,846
  • 7
  • 34
  • 51
  • You need to have a delimiter at the start and end of the regex. See http://php.net/manual/en/regexp.reference.delimiters.php. The `\d` also doesn't need to be in a character class, can just be `\d+`. – chris85 Feb 25 '17 at 15:40
  • Thank you @chris85 ! That solved my question ! – George Tudoran Feb 25 '17 at 15:50

0 Answers0