You are here

19 May 2017

Snippet shows you how to fix url query parameters starting with "&" instead of "?". This can be useful when you have to use "parse_url" function. It cannot detect query parameters when they start with ampersand instead of question mark. Since browsers are working with different logic, you might need this "hack".

Source code viewer
  1. // Hack for false urls, where query parameters start with "&" instead of "?".
  2. if (strpos($url, '?') === false) {
  3. // Count on str_replace accepts only variable, not a direct integer.
  4. $count = 1;
  5. $url = str_replace('&', '?', $url, $count);
  6. }
Programming Language: PHP