我从Elasticsearch获得了异常的PHP字符串。
步骤1:php curl
调用 flex 搜索以获取结果$value
,
第2步:php $value2 = strip_tags($value); // to remove all html tags
步骤3:var_dump($value2)
第4步:echo 'len='.mb_strlen($value2);
第5步:echo 'substr='.mb_substr($value2);
步骤3输出为:
string(974) " Ginger Never believe diet can help with cancer, but nice try. 2018-01-22 11:20:21 Gland Totally no snacks? there must be some snacks on the list, right... 2018-01-22 10:25:32 Reloated Article: How to Treat Bladder Cancer with Diet?"
步骤4的输出是:
len=974
步骤5的输出是:
Empty string
问题:
mb_strlen($value2) = 974
,当用mb_strlen
替换strlen
时,得到相同的974 php mb_substr($value2)
时,返回空字符串。使用substr,获得相同的空字符串。 是什么原因以及如何解决?
谢谢。
最佳答案
对不起,我解决了。
字符串的真实文本包含很多空格,并且不会在浏览器中呈现。删除它们,一切正常。
关于php - 异常的PHP字符串长度以及使用PHP搜索Elasticsearch时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53444088/