2013-11-21 2 views
0

CKEditor는 내 데이터베이스에 입력 된 내용에 새 줄을 추가합니다. 단,이 데이터를 한줄의 html로 javascript로 렌더링해야합니다. 내 PHP에서PHP에서 줄 바꿈 및 뉴 라인 제거

내가 가진 :

나는 새로운 라인을 제거하는 방법에서 찾을 수 있지만 여전히 페이지에두고 끝나는있어 거의 모든입니다
$tmpmaptext = $map['maptext'][$this->config->get('config_language_id')]; 
$tmpmaptext = html_entity_decode($tmpmaptext, ENT_QUOTES, 'UTF-8'); 
$tmpmaptext = str_replace(array('\r\n', '\n', '\r', '\t'), '', $tmpmaptext); 
$tmpmaptext = str_replace(PHP_EOL, '', $tmpmaptext); 

:

var infowindow01 = new google.maps.InfoWindow({ 
     content: '<div><h2>Title</h2> 

<p>Address line 1,<br /> 
Address line 2</p> 

<p>phone number</p> 

<p><a href="http://www.example.com" target="_blank">www.example.com</a></p> 
</div>' 

문자 사이의 일반 간격을 제거하지 않고이 새로운 행을 모두 어떻게 꺼낼 수 있습니까?

+0

줄 끝/공백/줄 끝과 같은 시퀀스를 제거하는 간단한 정규식을 작성하지 않으시겠습니까? –

+0

nl2br()을 사용해보십시오. http://php.net/manual/en/function.nl2br.php – Ali

+0

또한'$ tmpmaptext = preg_replace ('/ \ s + /', ', $ tmpmaptext);를 시도했지만, 간격. 나는 새로운 라인을 제거하기위한 정규식을 알지 못하거나 그것을 시도 할 것이다. –

답변

1

저는 '\ n'(슬래시 n) 문자열을 검색 할 str_replace에서 작은 따옴표를 사용하고 있기 때문입니다.

<div><h2>Title</h2><p>Address line 1,<br />Address line 2</p><p>phone number</p><p><a href="http://www.example.com" target="_blank">www.example.com</a></p></div> 
+0

또한 "\ t"를 검색 배열에서 ""(4 개 공백)으로 바꾸면 커다란 간격을 없앨 수 있습니다. – MikeJerome

0

이 트릭했다 :

$tmpmaptext = $map['maptext'][$this->config->get('config_language_id')]; 
$tmpmaptext = preg_replace('/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/', '', $tmpmaptext); 

제거 할 수 있었다 당신이 따옴표를 사용하는 경우는

$maptext = '<div><h2>Title</h2> 

<p>Address line 1,<br /> 
Address line 2</p> 

<p>phone number</p> 

<p><a href="http://www.example.com" target="_blank">www.example.com</a></p> 
</div>'; 

$no_newlines = str_replace(array("\n", "\r\n", "\r", "\t", " "), "", $maptext); 

echo($no_newlines); 

출력 ... 개행 문자 \ n을 변환합니다 나머지는 모두 완벽하게 렌더링됩니다.