清理用户提交的文本以使其良好且可读?
我有一个用 PHP+JS 构建的分类网站,我想自动清理和格式化用户提交的文本。用户真的是不可预测的,他们使用全部大写,逗号之间的错误间距,额外的制表符或间距甚至会导致 JSOn 错误......以及你可以想象的任何类型的样式错误......(我从未想象过!)
我想知道是否是否有任何关于如何清理文本以使其看起来至少像样的脚本或规则...
I have a classifieds website built in PHP+JS, and i'd like to clean and format automatically the text submitted by the users. the users are really unpredictable and they use all uppercase, wrong spacing between commas, extra tabs or spacing that causes even JSOn errors..,and any sort of style error you can imagine...(and i never imagined!)
i wonder wether is there any script or rules on how to clean up a text to look at least decent...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要知道的是如何清理输入并对其进行适当编码。快速谷歌一下就发现了这个。您永远不能信任浏览器中的任何东西,永远!一切都需要在服务器端进行检查,因此请从您的问题中了解。在我看来,这是 PHP 的缺点之一,因为其他技术会自动提供一定程度的保护。
关于编码,看看这个
What you need to know is how to sanitise input and encode it appropriately. A quick google has turned up this. You can never trust anything from the browser, ever! Everything needs checked server side so please learn from your question. This, in my opinion, is one of the failings of PHP as other technologies provide a certain degree of protection automatically.
With regards to encoding take a look at this
您可以通过多种方式过滤用户输入。例如,看看 lcfirst 函数。最好也考虑 htmlentities 和 striptags 函数来完全清理您的数据。
永远不要信任用户输入是一个值得遵守的好规则
There are various ways you can filter user input. Have a look at lcfirst function for example. It would be a good idea to consider htmlentities and striptags functions too to fully sanitise your data.
NEVER TRUST USER INPUT is a good rule to live by