-
Notifications
You must be signed in to change notification settings - Fork 0
/
url.php
47 lines (45 loc) · 1.02 KB
/
url.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace ScpoPHP;
/**
* url操作相关
* @link http://scpo-php.seventop.top/rewrite/
*/
class Url
{
/**
* 获取域名
* @param bool $port 是否包含端口
* @return string 域名
*/
static public function dmn($port)
{
static $dmn = array();
if (isset($dmn[1])) {
if ($port) return $dmn[1];
if (isset($dmn[0])) return $dmn[0];
} else {
$dmn[1] = $_SERVER['HTTP_HOST'];
if (substr_count($dmn[1], '.') === 2) $dmn[1] = substr($dmn[1], strpos($dmn[1], '.') + 1);
}
return $port
? $dmn[1]
: ($dmn[0] = ($pos = strpos($dmn[1], ':')) !== false
? substr($dmn[1], 0, $pos)
: $dmn[1]
);
}
/**
* 获取伪静态下访问的uri和get请求字符串
* @return array 数组,分别为uri和get请求
*/
static public function rewrite_uriget()
{
static $mem;
if ($mem) return $mem;
if (($pos = strpos($uri = $_SERVER['QUERY_STRING'], '&')) !== false) {
$get = substr($uri, $pos + 1);
$uri = substr($uri, 0, $pos);
} else $get = '';
return $mem = array($uri, $get);
}
}