- 网址管理增加删除协议和判断是否为Url方法

v6 v6.0.96
Chaim 4 years ago
parent 037b5d6a76
commit 2c9e67a71a

@ -1,6 +1,12 @@
## v6.0.96 / 2020-07-23
- 网址管理增加删除协议和判断是否为Url方法
## v6.0.95 / 2020-07-20
- 优化cache和session服务
## v6.0.94 / 2020-07-20
- 优化cache和session服务
## v6.0.93 / 2020-07-20
- 修复请求门面的判断微信和微信小程序环境函数名错误问题

@ -26,7 +26,7 @@ use think\db\exception\DbException;
/**
* 定义当前版本
*/
const VERSION = '6.0.95';
const VERSION = '6.0.96';
if (!function_exists('get_ip_info')) {
/**

@ -34,6 +34,8 @@ use think\Facade;
* @method static string lenCode(string $url) 编码
* @method static string deCode(string $url) 解码
* @method static string toParams(array $data) 格式化参数格式化成url参数
* @method static bool isUrl(string $url) 判断是否为Url
* @method static string deleteProtocol(string $url) 删除协议
*/
class Urls extends Facade
{

@ -70,4 +70,38 @@ class Urls
$buff = trim($buff, "&");
return $buff;
}
/**
* 判断是否为Url
* @param string $url
* @return bool
*/
public function isUrl(string $url): bool
{
$pattern = "#(http|https)://(.*\.)?.*\..*#i";
if (preg_match($pattern, $url)) {
return true;
} else {
return false;
}
}
/**
* 删除协议
* @param string $url
* @return string
*/
public function deleteProtocol(string $url): string
{
if (empty($this->isUrl($url))) {
return $url;
}
if (strpos($url, 'https://') !== false) {
return str_replace("https://", "//", $url);
}
if (strpos($url, 'http://') !== false) {
return str_replace("http://", "//", $url);
}
return $url;
}
}

Loading…
Cancel
Save