我只是偶然发现了这段代码:
/**
* @param $string
* @return bool
*/
protected static function isRubel($string)
{
$lString = strtolower($string);
/**
* @hint: The characters looking like "p" as in Petra are in fact instances of cyrillic "Er"!
*/
return strpos($string, 'руб') !== false || strpos($string, 'р') !== false || strpos($lString, 'rub') !== false;
}
作者很高兴提供一个提示,即该字符不是p
unicode符号р
,而是unicode符号。正如我所认为的是一个p
。
为了更清楚地说明字符是unicode符号,可以用不同的方式编写此代码吗?
从某种意义上说,编写unicode表示而不实际编写unicode字符。
我知道我可以定义一个字符串常量CRYLLIC_ER = р
,但是我正在寻找一个更通用的解决方案。
从PHP 7开始,您可以使用以下语法:
$str = "\u{####}";
在此之前,您可以使用UTF-8字节值使其变得明显:
$str = "\x##\x##";
但就我个人而言,我会做作者所做的,只是在评论中写下来。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句