加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – trim()没有捕获AJAX发布的数据值?

发布时间:2020-12-13 22:48:48 所属栏目:PHP教程 来源:网络整理
导读:我有一个满足的元素,onblur将它的价值发布到服务器上. 因为它是一个令人满意的,在重复的空格条目,而不是空格,它添加 nbsp;相反,生成的HTML可以是: Testing title nbsp; middle nbsp; entry nbsp; nbsp; 当从元素中使用.text()检索时,看起来像通常间隔(下划
我有一个满足的元素,onblur将它的价值发布到服务器上.

因为它是一个令人满意的,在重复的空格条目,而不是空格,它添加& nbsp;相反,生成的HTML可以是:

Testing title   middle   entry    

当从元素中使用.text()检索时,看起来像通常间隔(下划线标记空格):

Testing_title___middle___entry____

这个.text()值我发布到我的PHP后端.在那里,我经历了保存程序.因为我需要剪裁的字符串,基本修剪($title)没有削减它.

而且,我似乎无法理解它.

我也尝试了这个How to decode Unicode escape sequences like “u00ed” to proper UTF-8 encoded characters?,也没有帮助.

Chrome网络检查器,显示它通过此编码数据发送:

Testing+title+%C2%A0+middle+%C2%A0+entry+%C2%A0+%C2%A0

implode(‘,’,unpack(‘C *’,$title))返回:

84,101,115,116,105,110,103,// Testing
32,// space
116,108,// title
32,194,160,//  
32,109,100,// middle
32,32,114,121,// entry
32,160

$title最终只是一个$_POST [‘title’].

如何修剪此字符串中的所有空格?

最后,解决方案是:

$title = preg_replace('/s/iu',' ',$title)

解决方法

如何更换所有& nbsp;在开始修剪之前有空格?

$text= str_replace(' ',$text)

或者,如果要保持unicode安全,可以使用mb_eregi_replace
http://www.php.net/manual/en/function.mb-eregi-replace.php

编辑 – 第二种方法:

根据这个答案(https://stackoverflow.com/a/13992998/486780)

194 160 is the UTF-8 encoding of a NO-BREAK SPACE codepoint (the same codepoint that HTML calls ?).

So it’s really not a space,even though it looks like one. (You’ll see it won’t word-wrap,for instance.) A regular expression match for s would match it,but a plain comparison with a space won’t.

尝试使用正则表达式匹配它,如上所述?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读