简体   繁体   English

用php替换\\ n到字符串中的新行

[英]replace \n to new line in string with php

I just want to replace "\\n" characters to new line in a string using php, like that : 我只想使用php将“ \\ n”字符替换为字符串中的新行,如下所示:

string 'foo\n\nbar'

to

string 'foo

bar`

Anybody have an idea ? 有人有主意吗? Thanks. 谢谢。

use 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;
?>

Shows: 显示:

foo

bar

you can always Use 你可以随时使用

nl2br

function 功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM