Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只想使用 php 将 "\n" 字符替换为字符串中的新行,如下所示:
string 'foo\n\nbar'
至
string 'foo bar`
有人有想法吗?谢谢。
利用str_replace('\n', PHP_EOL, 'foo\n\nbar');
str_replace('\n', PHP_EOL, 'foo\n\nbar');
<?php header('Content-Type: text/plain'); $string = 'foo\n\nbar'; $string = str_replace('\n', PHP_EOL, $string); echo $string; ?>
显示:
foo bar
你可以随时使用
nl2br
功能