Authored by 郭成尧

'解决品牌店铺报错'

... ... @@ -1090,4 +1090,58 @@ class Helpers
{
return preg_match("/[\x7f-\xff]/", $str);
}
/**
* 将首字符为//的url转换为http://
*
* @param string $url 需要转换的url
* @return mixed
*/
public static function transHttpsUrl($url)
{
return preg_replace('/^\/\//', 'http://', $url);
}
/**
* http和https转换成//
* @param type $url 地址
* @return type string
*/
public static function getUrlSafe($url)
{
if (self::isStrpos(array('/special_', '/special/'), $url)) {
return $url;
}
return strtr($url, array('http://' => '//'));
}
/**
* 查找数组是否包含字符串中
* @param type $array 要查找的数组
* @param type $str 要搜索的字符串
* @return boolean
*/
public static function isStrpos($array = array(), $str = '')
{
foreach ($array as $val) {
if (strpos($str, $val) !== false) {
return true;
}
}
return false;
}
/**
* 获取当前页面是http还是https
* @return string
*/
public static function getHttpOrHttps() {
if ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ||
(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] === 443) ||
(isset($_SERVER['HTTP_REFERER']) && substr($_SERVER['HTTP_REFERER'], 0, 5) === 'https')) {
return 'https:';
}
return 'http:';
}
}
... ...