phpjavascripttextuser-generated-content

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


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...


Solution

  • 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