2016-08-12 4 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에 넣을 것인가? 왜 그런 차이가 없었 는가? –

+0

출력에 입력하지 않고 도망쳐 야한다 (XSS 공격을 막기 위해) –

+0

데이터베이스에서 더 많은 메모리를 차지하지 않습니까? @Marktwigg –

관련 문제