donglu8344812 2011-07-21 17:13
浏览 130

删除所有类型字符

I have constant problems with data where odd characters like  will show up in our database causing everything to break at some point down the line. I need to get a system in place that only allows specific characters through and ignores all of these crazy things that can be pasted from Microsoft Office. Is there something like this built in, or should I start from scratch?

  • 写回答

2条回答 默认 最新

  • doucai6663 2011-07-21 17:29
    关注

    Well, you can remove all such characters via e.g. $text = preg_replace('@[^\d\w\s,.;:]@', '', $text); where [^\d\w\s,.;:] is a set of characters to keep (\d\w\s means all digits, letters, and spaces). Amend the set with other characters you do want to keep.

    However, that is the wrong approach. You should instead ensure that your entire application is using and processing UTF-8 from ground up, so that you can store and handle those characters correctly. Making an ASCII or ISO Latin site in this day and age is just weird and essentially causes data loss due to cutting out characters that people actually use...

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100