[英]PHP Remove Unused Line Breaks Using nl2br
對於本示例,如何使用nl2br
函數刪除未使用的換行符:
Hello
Nice
預期輸出顯示:
Hello
Nice
再舉一個例子:
remove this unused line
remove this unused line
remove this unused line
Hello
remove this unused line
remove this unused line
remove this unused line
remove this unused line
預期輸出顯示:
Hello
因此意味着如果換行超過3行,則僅設置1個換行。
這是我的PHP代碼:
nl2br($string);
受過高等教育,但希望能奏效
$str = explode("\n", $str);
foreach($str as $val){
if(!empty($val)){
$result[] = $val;
}
}
$final = implode("\n", $result); //if you want line break use "<br>"
echo $final;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.