php在变量中查找新行并插入<;br>;
我有这样一个变量:php在变量中查找新行并插入<;br>;,php,regex,Php,Regex,我有这样一个变量: $Text= "Hello My Code" 所以我想做的是,在任何地方都有一个新行要插入,所以它看起来应该是这样的 $NewText = "Hello<br> My<br> Code" $NewText=“你好 我的 代码“ *您可以使用,或者: $text=“你好\nMy\nCode”; $newText=nl2br($text); $newText=pre
$Text= "Hello
My
Code"
所以我想做的是,在任何地方都有一个新行要插入,所以它看起来应该是这样的
$NewText = "Hello<br>
My<br>
Code"
$NewText=“你好
我的
代码“
*您可以使用,或者:
$text=“你好\nMy\nCode”;
$newText=nl2br($text);
$newText=preg\u replace(“/\r?\n/”、“
\n”、$text);
$newText=str\u replace(“\n”,“
\n”,$text);
您自己试过什么吗?
$text = "Hello\nMy\nCode";
$newText = nl2br($text);
$newText = preg_replace('/\r?\n/', "<br>\n", $text);
$newText = str_replace("\n", "<br>\n", $text);