开发者

Cleaning up user-submitted text to be good and readable?

开发者 https://www.devze.com 2023-02-04 03:57 出处:网络
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 spac

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 d开发者_如何学JAVAecent...


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消