replace \n with actual new line character code

前端 未结 5 1587
不知归路
不知归路 2021-02-19 03:49

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

相关标签:
5条回答
  • 2021-02-19 04:19

    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.

    0 讨论(0)
  • 2021-02-19 04:22
    str_replace("\\n","\n",$data);
    
    0 讨论(0)
  • 2021-02-19 04:25

    This might help a bit:

    echo('test\ntest'); shows as

    test test

    but echo("test\ntest"); shows as

    test

    test

    0 讨论(0)
  • 2021-02-19 04:26
    echo '<pre>'.str_replace('\n', "\n", $string).'</pre>';
    
    0 讨论(0)
  • 2021-02-19 04:28

    why not ...

    echo str_replace('\\n', PHP_EOL, "few lines\nof text here,\nblah, blah! etc!");
    
    0 讨论(0)
提交回复
热议问题