Created
October 21, 2016 04:25
-
-
Save victordit/17a267a1864f8347ce924574785f2475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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