search

Home  >  Q&A  >  body text

php怎样查找中文字符的位置呢?

这是啥这是啥2915 days ago985

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-10-01 00:36:27

    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.

    reply
    0
  • 怪我咯

    怪我咯2017-02-28 17:31:21

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


    reply
    0
  • Cancelreply