how to replace specified characters with space in a text file with php


text files name is 32viestit21.txt

  if (isset($_SESSION['username']))
  $fp = fopen('32viestit21.txt', 'a',1);

 // code here

  fwrite($fp, "$_SESSION[username]: $message".PHP_EOL);
        echo "<script>if ( window.history.replaceState ) {
  window.history.replaceState( null, null, window.location.href );

and the reason why i ask this is that my website has chat and the chat has xss problem and i have to fix it and chat works so that users inputs goes to txt file then php shows the txt file data.


Use htmlspecialchars() to encode the message.


Source: stackoverflow