I was having troubles with a simple thing, and after a long time trying to find out the problem I realize that str_replace does not work with simple quotes. This is my code:
<?php
$replaceNL1=str_replace("\n", "NEWLINE", $_POST['txt']);
echo $replaceNL1;
$replaceNL2=str_replace('\n', 'NEWLINE', $_POST['txt']);
echo '<hr>' . $replaceNL2;
?>
Only $replaceNL2 makes the replacement. On the first variable it acts like if there weren’t any str_replace(). This has never happened to me.
I am using UTF-8 charset.
Single and double quotes are a different thing in PHP.
PHP Strings:
So
"\n"is newline character, whereas'\n'are two character (literaly\n) without special meaning.