php - 如何从php中的unicode字符串中获取unicode字符

标签 php unicode

我想从 unicode 字符串中获取单个 unicode 字符。

例如:- $str = "पर्वतनि 你 回显 $str[0];

输出是:-

但我想在字符串的 0 索引处获取 char 'प'。

请帮助我如何获取 char 'प' 而不是 � 。

最佳答案

正如@deceze 所写,您需要使用 mb_substr为了得到一个字符,而不仅仅是一个字节。此外,您需要使用 mb_internal_encoding 设置内部编码。 .假设您的 .php 文件的编码是 UTF-8,则以下内容应该有效:

  mb_internal_encoding('utf-8');
  $str = "पर्वत निर्माणों में कोनसा संचलन कार्य करता है"; 
  echo mb_substr($str, 0, 1);

关于php - 如何从php中的unicode字符串中获取unicode字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27873995/

相关文章:

python - 代码从 python 2.7 到 3.5 (unicode)

c++ - 将 C 字符串从本地编码转换为 UTF8

php - 如果数据库丢失,设计模式可以优雅地失败

php - Windows 上的 ApiGen。无法运行 apigen 命令

ruby - 如何使用正则表达式匹配 unicode 字符代码点 12288

mysql - SQLite 和 MySQL 中使用 Unicode 代码点的 SQL 查询

php - mPDF : text align with p , h1 - 表中的 h6 不起作用

php - 如何从 xml 文件中跳过/删除无效的非 utf8 字符

javascript - document.getElementById 到 href 点击

Python:用CJKLIB将汉字转成拼音