【发布时间】:2014-08-11 11:52:57
【问题描述】:
questions answer here 将我引向了以下“问题”或挑战:
如果字符串是 UTF-8 编码并包含特殊字符,是否有可能从特定位置获取字符。
因此,对于包含字符串的非特殊字符,这是可行的:
$str = 'abcd';
echo $str{1}; // will print "b"
但是对于这样的字符串:
$str = 'abc★';
echo $str{1}; // will return "b"
echo $str{3}; // leads to a question mark
当然,PHP 文件是用 UTF-8 编码的,<meta charset="utf-8"> 在 HTML 的头部。
那么有什么解决方案可以让这种在字符串中捕获字符的方法起作用吗?
【问题讨论】: