I'm currently working on a website, where users can write articles with few format possibilities (like bold, italic, list...). I'm using a framework: CodeIgniter.
I'm a beginner, and I've heard some stuff about XSS. I would like to know what do you think about my implementation. I read this topic: What's the best method for sanitizing user input with PHP?
1) The user write his article, format it with BBCode. I'm using SCEditor.
2) When saving it into database, I'm using htmlspecialchars() to filter any suspect HTML tag. Am I supposed to do this when I'm saving data, or displaying data?
3) When I want to display the article on the website (for other uses for example), I convert BBCode tags into HTML tags.
Is it a right way to do it? Am I avoiding XSS?
I am obviously open to suggestions and advices.
Thanks for your answers