即使使用html_entity_decode,strpos也会对html实体返回false

问题描述

我正在尝试在可能包含或不包含html实体(例如)的字符串中搜索子字符串,但是即使使用html_entity_decode(),它仍会返回false

null

解决方法

 !== space (20),在解码C2 A0时,实际上等于2个字节的NO-BREAK SPACE。

U+00A0 | \xc2\xa0 |   | NO-BREAK SPACE

您可以使用以下方法进行测试:

<?php
//
$str='&nbsp;';
var_dump(html_entity_decode($str));

哪个会产生:string(2) " "

要解决此问题,请用正常的nbsp空间替换该空间:

var_dump(strpos(str_replace("\xc2\xa0",' ',html_entity_decode($str)),'online shop'));

结果:int(0)

https://3v4l.org/WXTGR

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...