2016-08-12 10 views
0

黒の新しい行を

There is a pleasure in the pathless woods, 
There is a rapture on the lonely shore, 
There is society, where none intrudes. 

され削除しますTextは、私はそれが

012になりたい

By the deep Sea, and music in its roar: 


I love not Man the less, but Nature more, 



From these our interviews, in which I steal 

です

By the deep Sea, and music in its roar: 
I love not Man the less, but Nature more, 
From these our interviews, in which I steal 

どのように私はそれをPHPで達成できますか?あなたはまた、この

str_replace(array("\n", "\r"), '', $text); 

あなたが入力ではなく出力にエスケープしている何らかの理由でstr_replaceを使用することができます

+4

可能な重複[?私はPHPでのテキストから空白行を削除するにはどうすればよいです] (http://stackoverflow.com/questions/709669/how-do-i-remove-blank-lines-from-text-in-php) – Script47

+0

私はそれをしたが、うまくいかなかった。@ Script47 –

+0

あなたのhtml出力 – Takarii

答えて

0

簡単な解決策は、preg_replace()を使用することです。これは、任意の複数の行を見つけて、単一の新しい行でそれらを置き換えます:

$Text = preg_replace("/[\r\n]+/", "\n", $Text); 

デモhereを参照してください:

$Text = "There is a pleasure in the pathless woods, 


There is a rapture on the lonely shore, 


There is society, where none intrudes."; 


$Text=trim($Text); 
$Text=preg_replace("/[\r\n]+/", "\n", $Text); 

echo $Text; 
+0

ありがとう!出来た –

0

+0

私はそれをdb thatsに挿入しています。なぜなら、それは違いがありませんでした。 –

+0

出力に入力しないでエスケープすると(XSS攻撃を防ぐ) –

+0

データベースでもっと多くのメモリを使いませんか? @Marktwigg –

関連する問題

 関連する問題