I'm pulling content from a DB that has been sanitized using mysql_real_escape_string. Accordingly the new line characters now appear as "\n". The issue is that this content is displayed to users inside a < pre > tag so I cannot replace \n with < br/> for instance.
I suppose I could replace \n with the actual utf8 character code before inserting the result inside the < pre>.
Can somoneone assist here? Not using mysql_real_escape_string isn't really an option due to security policy.
Thanks.
The newline character ( \n ) is called an escape sequence, and it forces the cursor to change its position to the beginning of the next line on the screen. This results in a new line.
Today I learned How to find and replace with a newline in Visual Studio Code. In the local searchbox ( Ctrl + F ) you can insert newlines by pressing Ctrl + Enter . If you use the global search ( Ctrl + Shift + F ) you can insert newlines by pressing Shift + Enter .
It can be None, '', '\n', '\r', and '\r\n'. It works as follows: On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in '\n', '\r', or '\r\n', and these are translated into '\n' before being returned to the caller.
echo '<pre>'.str_replace('\n', "\n", $string).'</pre>';
str_replace("\\n","\n",$data);
why not ...
echo str_replace('\\n', PHP_EOL, "few lines\nof text here,\nblah, blah! etc!");
I'm pulling content from a DB that has been sanitized using mysql_real_escape_string. Accordingly the new line characters now appear as "\n"
If you've not done anything to the raw data pulled back from the database then the ptoblem is that it has been 'sanitized' twice when inserted.
C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With