Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php在变量中查找新行并插入<;br>;_Php_Regex - Fatal编程技术网

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);