0

I am new to Mysqli_* and I am getting these errors:

(PHP 4 >= 4.0.5, PHP 5, PHP 7)

preg_replace_callback — Perform a regular expression search and replace using a callback

$url = preg_replace('/\/index.php$/i', '', reset($url = explode('?', $_SERVER['HTTP_REFERER'])));

I've read the PHP site and I am just not seeing something. I've tried using preg_replace_callback and splitting the striing and still not working.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 1
    What does this have to do with `mysqli_*`? – Barmar Sep 09 '19 at 21:33
  • 2
    Why do you think you need to use `preg_replace_callback`? That's needed if you need to calculate the replacement dynamically, not if you just want to replace with an empty string. – Barmar Sep 09 '19 at 21:34
  • 1
    What exactly are you trying to do? – Barmar Sep 09 '19 at 21:34
  • The only argument that has to be passed by reference to `preg_replace()` is the optional 5th argument, a variable that receives the count of replacements that were made. You shouldn't get this error when only passing 3 arguments. – Barmar Sep 09 '19 at 21:37
  • the error is: Strict Standards: Only variables should be passed by reference . not Mysqli typed the wrong heading - sorry – ttorrez Sep 09 '19 at 21:54
  • 1
    The problem is with the argument to `reset()`. It needs to be a variable, not a variable assignment. – Barmar Sep 09 '19 at 22:07
  • 1
    Put the assignment on the previous line. – Barmar Sep 09 '19 at 22:08
  • You _actually_ should just do... `$url = preg_replace('/(?:\/index\.php)?\??.*$/i', '', $_SERVER['HTTP_REFERER'])` This will remove `/index.php`(if it exists) and anything after the first question mark. – mickmackusa Sep 09 '19 at 22:29

1 Answers1

0

There's no need for the call to reset(), just put the call to explode() there.

$url = preg_replace('/\/index\.php$/i', '', explode('?', $_SERVER['HTTP_REFERER']));
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Please escape the dot for educational purposes. I think the OP wants to target the url before the querystring `[0]`. – mickmackusa Sep 09 '19 at 22:23