I’m new to programming, and I’m trying to apply the htmlspecialchars to the script below, but all attempts have just resulted in error messages. I believe it should be something like: echo htmlspecialchars($lines), but not sure how this would apply to the code below, or if I should use something else.
The end result should convert the text from the .txt file from :
Anna said she \”wouldn\’t go to Hannah\’s house\”.
to:
Anna said she “wouldn’t go to Hannah’s house”.
<?php
$lines = file('users.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
uasort($lines, 'strnatcasecmp');
foreach ($lines as $num => $line) {
printf("%s (line #%d)<br>", $line, $num);
}
?>
stripslashes()will remove the slashes from that content for you.Even though
htmlspecialchars()won’t deal with the slashes I included them since it’s good form to use it on user generated data (I’m assuming what is in the text file user generated data).