Skip to content

Instantly share code, notes, and snippets.

@victordit
Created October 21, 2016 04:25
Show Gist options
  • Save victordit/17a267a1864f8347ce924574785f2475 to your computer and use it in GitHub Desktop.
Save victordit/17a267a1864f8347ce924574785f2475 to your computer and use it in GitHub Desktop.
<?php
/**
* @return string
* @param string $url
* @param array $params
*/
public function removeQueryString($url,$params=array())
{
if(count($params)){
foreach ($params as $value) {
$pattern = "#(&|\?)".$value."=[^&]+#";
$url =preg_replace($pattern,'', $url);
if(strrpos($url, '?')===false){
$url = preg_replace('#&#','?',$url, 1);
}
}
}else{
$url = substr($url, 0, strpos($url, "?"));
}
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment