Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safe way to escape iframe srcdoc value in PHP?

Which PHP function is suited to escape HTML for usage in <iframe srcdoc="???">?

I found two candidates: htmlspecialchars() and htmlentities(). Which one should be used to allow any possible HTML code to be escaped properly?

like image 851
Silicomancer Avatar asked Dec 14 '25 01:12

Silicomancer


1 Answers

htmlspecialchars() does everything you need it too. htmlentities() is for special use cases, like Chinese characters, where you may want to escape them, even though it is not 100% required. htmlspecialchars() seems to be sufficient to protect you from any type of XSS.

like image 88
Bardi Harborow Avatar answered Dec 16 '25 19:12

Bardi Harborow