当字符串包含扩展 ASCII 代码时,为什么 `mb_eregi_replace` return NULL?
Why does `mb_eregi_replace` return NULL when the string contains extended ASCII codes?
使用PHP v7.1.5,为什么PHP功能mb_eregi_replace
return NULL if the string contains extended ASCII code A0
("Non-breaking space" according to www.ascii-code.com)?
$ php -a
Interactive shell
php > $t = mb_eregi_replace('d', '', "do\xA0not");
php > echo $t;
php > if( $t === null ) { echo "is null"; } else { echo "replace worked"; }
is null
php > $t = mb_eregi_replace('d', '', "do not");
php > echo $t;
o not
php > if( $t === null ) { echo "is null"; } else { echo "replace worked"; }
replace worked
在将它传递给 mb_eregi_replace
之前阅读 this article (specifically the "What to Do to Convert Extended ASCII to UTF-8" section) shows that passing the string to utf8_encode
解决了问题。
$ php -a
Interactive shell
php > $t = mb_eregi_replace('d', '', utf8_encode("do\xA0not"));
php > echo $t;
o not
使用PHP v7.1.5,为什么PHP功能mb_eregi_replace
return NULL if the string contains extended ASCII code A0
("Non-breaking space" according to www.ascii-code.com)?
$ php -a
Interactive shell
php > $t = mb_eregi_replace('d', '', "do\xA0not");
php > echo $t;
php > if( $t === null ) { echo "is null"; } else { echo "replace worked"; }
is null
php > $t = mb_eregi_replace('d', '', "do not");
php > echo $t;
o not
php > if( $t === null ) { echo "is null"; } else { echo "replace worked"; }
replace worked
在将它传递给 mb_eregi_replace
之前阅读 this article (specifically the "What to Do to Convert Extended ASCII to UTF-8" section) shows that passing the string to utf8_encode
解决了问题。
$ php -a
Interactive shell
php > $t = mb_eregi_replace('d', '', utf8_encode("do\xA0not"));
php > echo $t;
o not