How to find the location of Chinese characters in php? -PHP Chinese website Q&A-How to find the position of Chinese characters in PHP? -PHP Chinese website Q&A
Let’s take a look and learn.
1、中文字符是gbk(gb2312)
有两种解决方法
第一种:
将PHP保存为ASCII编码,然后使用strpos查找,如:
strpos($curl_res, ‘哈哈’)
第二种:
将PHP保存为UTF-8无BOM编码,然后转换字符串编码为UTF-8,再查找,如:
$curl_res = mb_convert_encoding($curl_res, ‘utf-8′, ‘gbk’);
mb_strpos($curl_res, ‘哈哈’);
2、中文字符是UTF-8
将PHP保存为UTF-8无BOM编码,然后使用strpos查找,如:
将PHP保存为ASCII编码,然后转换字符串编码为gbk,再查找,如:
$curl_res = mb_convert_encoding($curl_res, ‘gbk’, ‘utf-8′);
How to find the location of Chinese characters in php? -PHP Chinese website Q&A-How to find the position of Chinese characters in PHP? -PHP Chinese website Q&A
Let’s take a look and learn.
1、中文字符是gbk(gb2312)
有两种解决方法
第一种:
将PHP保存为ASCII编码,然后使用strpos查找,如:
strpos($curl_res, ‘哈哈’)
第二种:
将PHP保存为UTF-8无BOM编码,然后转换字符串编码为UTF-8,再查找,如:
$curl_res = mb_convert_encoding($curl_res, ‘utf-8′, ‘gbk’);
mb_strpos($curl_res, ‘哈哈’);
2、中文字符是UTF-8
有两种解决方法
第一种:
将PHP保存为UTF-8无BOM编码,然后使用strpos查找,如:
strpos($curl_res, ‘哈哈’)
第二种:
将PHP保存为ASCII编码,然后转换字符串编码为gbk,再查找,如:
$curl_res = mb_convert_encoding($curl_res, ‘gbk’, ‘utf-8′);
mb_strpos($curl_res, ‘哈哈’);