php - 异常的PHP字符串长度以及使用PHP搜索Elasticsearch时

标签 php string elasticsearch substr strlen

我从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



问题:
  • 字符总数约为231。显然少于974。
  • mb_strlen($value2) = 974,当用mb_strlen替换strlen时,得到相同的974
  • 调用php mb_substr($value2)时,返回空字符串。使用substr,获得相同的空字符串。

  • 是什么原因以及如何解决?
    谢谢。

    最佳答案

    对不起,我解决了。
    字符串的真实文本包含很多空格,并且不会在浏览器中呈现。删除它们,一切正常。

    关于php - 异常的PHP字符串长度以及使用PHP搜索Elasticsearch时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53444088/

    相关文章:

    php - Codeigniter HMVC 模块和 javascript 文件

    php - 无法将图像上传到应用程序 Codeigniter 外部的文件夹

    python - 循环比较字符串列表元素与字符串列表子元素的有效方法

    ios - 范围字符串 : always returns the same range for a recurring character

    php - 出于安全原因检查常量

    PHP "Use of undefined constant length"数组到字符串的转换

    c - C中字符串中的字母互换

    elasticsearch - 查询DSL Elasticsearch不起作用

    amazon-web-services - 字符串数据类型的 Elasticsearch 查询

    elasticsearch - 使用较高的页面排名和较低的URL对结果elasticsearch排序