2017-04-25 5 views
0

나는 사이의 모든 공백을 제거하기 위해 노력하고있어 제거BBCode의 사이의 모든 공백

[code]http://stackoverflow.com/questions/ask[/code] 


[code]http://stackoverflow.com/questions/ask[/code] 
lorem ipsum 
[code]http://stackoverflow.com/questions/ask[/code] 

나는 싶어 :

[code]http://stackoverflow.com/questions/ask[/code] 
[code]http://stackoverflow.com/questions/ask[/code] 
lorem ipsum 
[code]http://stackoverflow.com/questions/ask[/code] 

내 코드를 :

$string = preg_replace('@\[code\]\[(s+)\]\[\/code\]@si', '', $string); 
+0

공백이 아닌 줄 바꿈에 대해 자세히 설명합니다. 그리고 당신의 정규식은'code' 태그 사이를 쳐다 보지만 결과는 태그 밖에서 조작됩니다. – JustOnUnderMillions

+0

줄 바꿈 ('\ n')을 제거하고 싶습니다 – modsfabio

+0

@modsfabio 정확히 –

답변

0

공백 또는 모든 공백을 의미합니까? 단지 공간에 대한

, 사용 않는 str_replace : 공백 문자를 사용 preg_replace이다 들어

$string = str_replace(' ', '', $string); 

:

$string = preg_replace('/\s+/', '', $string); 
+0

그냥 공백을 제거하고 싶습니다. [코드 /] [코드] –

0

당신은 정규식 preg_replace이다를 (사용, 같은 것을 할 수있다) :

$text = preg_replace('/\[(.*?)\]\s*\[/', '[\1][', $text); 
+0

[코드] 태그로 어떻게 제한합니까? $ template = preg_replace ('@ \ [(. *?) \] \ s * \ [@', '[코드] [', $ 템플릿); –