Php 与nl2br类似的函数,但使用<;w:br/>;标记并删除任何打断线

Php 与nl2br类似的函数,但使用<;w:br/>;标记并删除任何打断线,php,string,newline,str-replace,Php,String,Newline,Str Replace,他有一个例子 <?php $string = "This\r\nis\n\ra\nstring\r"; echo nl2br($string); ?> 这是回报 This<br /> is<br /> a<br /> string<br /> 这个 是 a 字符串 我想要的是能够用这个替换所有的换行符。我不想看到更多的新词 换句话说,我想回去 This<w:br />is<w:br />a<w:b

他有一个例子

<?php
$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
?>

这是回报

This<br />
is<br />
a<br />
string<br />
这个

a
字符串
我想要的是能够用这个
替换所有的换行符。我不想看到更多的新词

换句话说,我想回去

This<w:br />is<w:br />a<w:br />string<w:br />
thisisString

我怎样才能做到这一点呢?

当我把问题写了一半的时候,我找到了答案

以防万一,其他人也有同样的问题

/**
 *
 * Replace newline
 *
 * Replace newlines with something else
 *
 * @param $subject String The subject we are searching for newlines and replace
 * @param $replace String The replacement for the newlines
 * @return String The new subject with the newlines replaced
 */     
    function replaceNewLines($subject, $replace) {
        return str_replace(array("\r\n", "\n\r", "\n", "\r"), $replace, $subject);
    }
然后调用函数

$replacedContent = replaceNewLines($content, "<w:br />");
$replacedContent=replaceNewLines($content,”);

str_replace()
接受数组作为参数(因此您可以使用
返回str_replace([“\r\n”、“\n\r”、“\r”]、$replace、$subject);
)谢谢大家!太棒了:)