php怎样查找中文字符的位置呢?
这是啥
这是啥 2017-02-28 17:30:56
0
2
981
这是啥
这是啥

reply all(2)
数据分析师

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, ‘哈哈’);


Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template