2

http://sg2.php.net/manual/en/function.nl2br.phpに例があります

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

これは戻ります

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

私が望むのは、すべての改行を this に置き換えること<w:br />です。そして、私はこれ以上改行を見たくありません。

というか、戻りたい

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

どうすればこれを達成できますか?

4

1 に答える 1

2

質問を途中まで書いていたら、答えがわかりました。

念のため、他の誰かが同じ質問をしています。

/**
 *
 * 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 />");
于 2013-09-10T07:57:53.860 に答える