当字符串包含扩展的ASCII代码时,为什么`mb_eregi_replace`返回NULL?

时间:2017-07-25 16:49:28

标签: php ascii multibyte

使用PHP v7.1.5,如果字符串包含扩展的ASCII代码A0("非中断空格"根据{{3),为什么PHP函数mb_eregi_replace返回NULL }})?

$ 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

1 个答案:

答案 0 :(得分:0)

阅读this article(特别是“如何将扩展ASCII转换为UTF-8”部分)显示在将字符串传递给mb_eregi_replace之前将其传递给$ php -a Interactive shell php > $t = mb_eregi_replace('d', '', utf8_encode("do\xA0not")); php > echo $t; o not 解决了问题

DataColumn[] columns = tbl.Columns.Cast<DataColumn>().ToArray();
bool anyFieldContainsPepsi = tbl.AsEnumerable()
    .Any(row => columns.Any(col => row[col].ToString() == "PEPSI"));