123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- class Url{
- public static $exclude = array();
-
- public static function getParams(){
- $get = $_GET;
-
- if(self::$exclude){
- foreach(self::$exclude as $val){
- unset($get[$val]);
- }
- }
-
- return $get;
- }
- public static function setParams($params = array()){
- if($params){
- $get = self::getParams();
-
- $url = explode("?", $_SERVER["REQUEST_URI"], 2);
- $append = "";
- $get = array_merge($get, $params);
-
- foreach($get as $key => $val){
- if(is_array($val))
- continue;
-
- $key = trim($key);
- $val = trim($val);
-
- if(empty($key))
- continue;
- $append .= "&{$key}={$val}";
- }
-
- return "{$url[0]}?".substr($append, 1);
- }
-
- return $_SERVER["REQUEST_URI"];
- }
- public static function delParams($params = array(), $withSymbol = false){
- if($params){
- $get = self::getParams();
-
- $url = explode("?", $_SERVER["REQUEST_URI"], 2);
- $append = "";
-
- foreach($params as $k){
- if(Str::isBlank($k))
- continue;
-
- if(isset($get[$k]))
- unset($get[$k]);
- }
-
- if($get){
- foreach($get as $key => $val){
- $append .= "&{$key}={$val}";
- }
- }
-
- $url = $append ? "{$url[0]}?".substr($append, 1)."&" : "{$url[0]}?";
- }
- else{
- $url = self::getUrl().self::getSymbol();
- }
-
- if(!$withSymbol)
- $url = substr($url, 0, -1);
-
- return $url;
- }
-
- public static function delParam($param){
- return self::delParams(array($param));
- }
-
- public static function clean(){
- $get = self::getParams();
-
- if($get){
- $url = explode("?", $_SERVER["REQUEST_URI"], 2);
- $append = "";
- $count = 0;
-
- foreach($get as $key => $val){
- if(!is_string($val))
- continue;
-
- if(trim($val) === "")
- $count++;
- else
- $append .= "&{$key}={$val}";
- }
-
- $url = $append ? "{$url[0]}?".substr($append, 1) : $url[0];
- if($count)
- header("location: {$url}");
- }
- }
-
- public static function getPath(){
- $url = explode("?", $_SERVER["REQUEST_URI"], 2);
- return $url[0];
- }
-
- public static function getAppend(){
- $append = "";
-
- if($get = self::getParams()){
- foreach($get as $key => $val){
- if(is_array($val))
- continue;
-
- $append .= "&{$key}={$val}";
- }
-
- $append = "?".substr($append, 1);
- }
-
- return $append;
- }
-
- public static function getUrl(){
- return self::getPath().self::getAppend();
- }
-
- public static function getSymbol(){
- return strpos($_SERVER["REQUEST_URI"], "?") === false ? "?" : "&";
- }
- }
|