|
@@ -141,6 +141,15 @@ function _require($files)
|
|
|
return \Qii\Autoloader\Import::requires($files);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 检测字符的编码
|
|
|
+ *
|
|
|
+ * @param string $str
|
|
|
+ * @return false|string
|
|
|
+ */
|
|
|
+function detectEncode($str) {
|
|
|
+ return mb_detect_encoding($str, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
|
|
|
+}
|
|
|
/**
|
|
|
* 将字符串转换成指定编码
|
|
|
*
|
|
@@ -150,7 +159,7 @@ function _require($files)
|
|
|
*/
|
|
|
function convertCode($str, $to)
|
|
|
{
|
|
|
- $fromCode = mb_detect_encoding($str, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
|
|
|
+ $fromCode = detectEncode($str);
|
|
|
if($fromCode == $to) return $str;
|
|
|
return mb_convert_encoding($str, $to, $fromCode);
|
|
|
}
|
|
@@ -184,7 +193,7 @@ function toGBK($str)
|
|
|
* @param string $needle
|
|
|
* @return bool
|
|
|
*/
|
|
|
-function str_contains(string $haystack, string $needle)
|
|
|
+function strContains(string $haystack, string $needle)
|
|
|
{
|
|
|
return '' === $needle || false !== strpos($haystack, $needle);
|
|
|
}
|
|
@@ -195,7 +204,7 @@ function str_contains(string $haystack, string $needle)
|
|
|
* @param string $needle
|
|
|
* @return bool
|
|
|
*/
|
|
|
-function str_starts_with($haystack, $needle)
|
|
|
+function strStartsWith($haystack, $needle)
|
|
|
{
|
|
|
return 0 === strncmp($haystack, $needle, \strlen($needle));
|
|
|
}
|
|
@@ -206,7 +215,7 @@ function str_starts_with($haystack, $needle)
|
|
|
* @param string $needle
|
|
|
* @return bool
|
|
|
*/
|
|
|
-function str_ends_with($haystack, $needle)
|
|
|
+function strEndsWith($haystack, $needle)
|
|
|
{
|
|
|
if ('' === $needle || $needle === $haystack) {
|
|
|
return true;
|