I have a function in my function library called sanitse. It takes one argument of a string and returns the sanitised string back.
function sanitise($data){
return htmlentities(mysql_real_escape_string($data));
}
I am developing a forum and I need to sanitise data that is submitted as text. (it is stored in a database). There are problems arising though. When the data is stored new lines are represented as \r\n and that is appearing on the thread after it is retrieved. There should be a new line instead. nl2br doesn't sort it out and I read on another post that this should be tackled at the source of the problem (the function) rather than 'hacking' a solution to correct it.
If I don't sanitise the data, the comment is displayed correctly. But that is of course not secure.
Any suggestions would be gratefully received.