Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.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>;在以下场景中是否按标记\n?_Php_Preg Replace_Preg Match_Newline_Line Breaks - Fatal编程技术网

Php 为什么编写的函数将文本变为空白而不是替换<;br>;在以下场景中是否按标记\n?

Php 为什么编写的函数将文本变为空白而不是替换<;br>;在以下场景中是否按标记\n?,php,preg-replace,preg-match,newline,line-breaks,Php,Preg Replace,Preg Match,Newline,Line Breaks,我有一个变量,比如$text,如下所示: $text = "Line one <br>Line two<br>Line threee<br>Line Fourrr<br>Line Fiveee"; function br2nl($buff = '') { $buff = mb_convert_encoding($buff, 'HTML-ENTITIES', "UTF-8"); $buff = preg_replace('#&l

我有一个变量,比如
$text
,如下所示:

$text = "Line one <br>Line two<br>Line threee<br>Line Fourrr<br>Line Fiveee";
  function br2nl($buff = '') {
    $buff = mb_convert_encoding($buff, 'HTML-ENTITIES', "UTF-8");
    $buff = preg_replace('#<br[/\s]*>#si', "\n", $buff);
    $buff = trim($buff);

    return $buff;
  }
 "Line one\nLine two\nLine threee\nLine Fourrr\nLine Fiveee"
以下是对该函数的调用:

$text = br2nl($text);
现在如果我
echo$text我变空白了。预期结果应该是所有的

标记都被
替换。预期产出应如下所示:

$text = "Line one <br>Line two<br>Line threee<br>Line Fourrr<br>Line Fiveee";
  function br2nl($buff = '') {
    $buff = mb_convert_encoding($buff, 'HTML-ENTITIES', "UTF-8");
    $buff = preg_replace('#<br[/\s]*>#si', "\n", $buff);
    $buff = trim($buff);

    return $buff;
  }
 "Line one\nLine two\nLine threee\nLine Fourrr\nLine Fiveee"

那我该怎么办呢?

代码对我来说很好!您还想使用
\n
还是
?@Rizier123:我想要\n1。请确保向我们展示完整真实的代码2。确切的输出是什么:
$text=br2nl($text);变量转储($text)(从源代码中获取输出)?preg_replace(“
”,“/\\n/m”,$string);使用上面给出的代码。希望它能起作用。@PHPWeblineindia你知道第二个参数不是正则表达式吗?!