-1

假设我有如下字符串 $comments = Windows Embedded Compact (Windows CE) 或 Windows Server。已停产的 Windows 系列包括 Windows 9x 和 Windows Mobile。[CR][LF] [CR][LF] 微软于 1985 年 11 月 20 日推出了名为 Windows 的操作环境,作为 MS-DOS 的图形操作系统外壳,以响应对图形用户界面 (GUI) 日益增长的兴趣。

注意:[CR][LF] 是为问题手动添加的。当任何用户在我们正在观察这些元素的评论富文本区域框中复制并粘贴任何 html 内容时,我发现了这个问题。

有没有办法我们可以在 PHP 中用 \n\r 替换它们。

我尝试过这样的事情

$comments = preg_replace("/\r\n\r\n|\r\r|\n\n/", "<br />", $comments);

它没有给我任何正确的结果。

4

1 回答 1

0

假设您想用 [CR][LF] 替换 [CR] 和 [LF] 的任何组合(即\r\n, not \n\r),试试这个:

$string = ".....[CR].....[LF]...[CR][LF].....[CR][CR].......[LF][LF].......";
$result = preg_replace('/\r\n|\n\r|\r|\n/', '\r\n', $string);
于 2016-01-20T12:17:19.223 回答