If you are not using a template engine (which I highly recommend to prevent XSS attacks), you need to delete all user data using the following:
htmlspecialchars($string, ENT_QUOTES);
, nonce - , script :
<script nonce="myRandomString"></script>
CSP PHP:
header('Content-Security-Policy', 'script-src 'nonce-myRandomString' 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:; object-src 'none');
script ( Chrome, CSP 3 , ). , 100%, .
, nonce .
Symfony. Symfony CSP.