首頁  >  文章  >  後端開發  >  php如何解決回車換行符的轉換問題

php如何解決回車換行符的轉換問題

coldplay.xixi
coldplay.xixi原創
2020-09-30 09:29:544714瀏覽

php解決回車換行符號轉換的方法:1.使用file函數,程式碼為【$list = file($intstr)】;2、使用replace函數,程式碼為【ereg_replace("\r\ n", "", $value);】。

php如何解決回車換行符的轉換問題

php解決回車換行符號轉換的方法:

方法1  :nl2br(PHP 4, PHP 5 )

nl2br — Inserts HTML line breaks before all newlines in a string

方法2:可以採用file()函數,範例如下

function fmtfilenl($intstr)
{
 $list = file($intstr);
 foreach($list as $row) {
    $outstr=$outstr.$row.'
';
 }
 return $outstr;
}

方法3:

$a = preg_replace("/[\r\n]+/", ',', $a);或$a = join(',', split("[\r\n]+", $a));

方法4:

ereg_replace("\r\n", "", $value);

最後一個知道的,PHP code

str_replace("\n", '', str_replace("\r\n", "\n", $a));
or
str_replace(PHP_EOL, "\n", $a )

想了解更多程式設計學習,請關注php培訓欄位!

#

以上是php如何解決回車換行符的轉換問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn