Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use: htmlspecialchars? [duplicate]

Tags:

php

mysql

I need to convert my strings to special characters using:

 htmlspecialchars

My question is, should I convert my data before submitting it to a database or should I convert it before I display it?

like image 669
panthro Avatar asked Dec 21 '22 04:12

panthro


1 Answers

You should sanitize data before inserting it into a database, and escape it on retrieval.

htmlspecialchars is used for escaping, so it should be after you’ve fetched it from the database.

like image 129
Martin Bean Avatar answered Dec 22 '22 19:12

Martin Bean