2016-06-03 2 views
0

형식 문자열이 마음에 들면, PHP로 단락이 잘된 단락처럼 어떻게 바꿀 수 있습니까? 텍스트 맞춤과 같은 예제입니다 : CSS와 브라우저 창의 전폭을 정당화합니까? 결과에서PHP 문자열의 단락 스타일

<?php 

$text = "It is a long 
established fact that a reader 
will be distracted 
by the readable content of a 
page when looking at its layout. 
The point of using Lorem Ipsum 
is that it has a 
more-or-less normal distribution of 
letters, as opposed to using 'Content here, 
content here', making it look like readable English. 
Many desktop publishing packages and web 
page editors now use Lorem Ipsum as their 
default model text, and a search for 'lorem ipsum' 
will uncover many web sites still in their infancy. 
Various versions have evolved over the years, 
sometimes by accident, sometimes on 
purpose (injected humour and the like). 
"; 
?> 

나는이 형식이 단락을 설정하려면 :

그것은 레이아웃을 볼 때 독자가 페이지의 읽을 수있는 내용으로 산만됩니다 긴 설립 사실이다. Lorem Ipsum 사용의 요점은 '여기에있는 내용, 여기에있는 내용'을 사용하는 것과 대조적으로 글자의 정규 분포가 더 많아 지거나 읽을 수있는 영어처럼 보이게한다는 것입니다. 많은 데스크탑 게시 패키지와 웹 페이지 편집기는 이제 Lorem Ipsum을 기본 모델 텍스트로 사용하고 'lorem ipsum'을 검색하면 아직 초기 단계에있는 많은 웹 사이트가 검색됩니다. 다양한 버전이 수년 동안, 때로는 우연히, 때로는 의도적으로 (주입 된 유머 등) 진화 해 왔습니다.

+0

<p> 태그에 변수를 포장하고 적용 –

답변

1

PHP는 텍스트의 서식 지정과 표시까지는 거의 처리하지 않습니다. 위의 텍스트를 $ 텍스트 개체에 저장하면 브라우저 창에 직접 출력하면 바로 아래에 표시됩니다. PHP에서 출력 한 텍스트의 서식을 지정하려면 CSS와 HTML을 사용하는 것이 좋습니다.

또한 $ text 개체에 할당 할 때 표시되는 모든 줄 바꿈은 PHP에 의해 보존되지 않습니다. 텍스트 문자열을 저장할 때 새 줄을 만들 것을 명시 적으로 선언해야합니다.

0

은 (그들이 당신의 첫 번째 텍스트에 표시되지 않습니다.) $ 텍스트에서/N/R 문자를 제거 스타일

<?php 

$text = "It is a long 
established fact that a reader 
will be distracted 
by the readable content of a 
page when looking at its layout. 
The point of using Lorem Ipsum 
is that it has a 
more-or-less normal distribution of 
letters, as opposed to using 'Content here, 
content here', making it look like readable English. 
Many desktop publishing packages and web 
page editors now use Lorem Ipsum as their 
default model text, and a search for 'lorem ipsum' 
will uncover many web sites still in their infancy. 
Various versions have evolved over the years, 
sometimes by accident, sometimes on 
purpose (injected humour and the like). 
"; 

$text = "<p style='text-align:justify'>$text</p>"; 

echo $text; 

<p style='text-align:justify'>It is a long 
 
established fact that a reader 
 
will be distracted 
 
by the readable content of a 
 
page when looking at its layout. 
 
The point of using Lorem Ipsum 
 
is that it has a 
 
more-or-less normal distribution of 
 
letters, as opposed to using 'Content here, 
 
content here', making it look like readable English. 
 
Many desktop publishing packages and web 
 
page editors now use Lorem Ipsum as their 
 
default model text, and a search for 'lorem ipsum' 
 
will uncover many web sites still in their infancy. 
 
Various versions have evolved over the years, 
 
sometimes by accident, sometimes on 
 
purpose (injected humour and the like). 
 
</p>

+0

나는 그것을 안다 :하지만 나는 CSS 솔루션을 사용하지 않는다. PHP 함수를 사용하여이를 수행하는 방법을 알아야합니다. –

+0

@CihanZengin PHP는 서버 수준의 작업을 수행 할 수있는 서버 측 스크립트입니다. 프런트 엔드 프레젠테이션은 CSS에서 처리합니다. –

+0

렌더링은 브라우저에서 전적으로 클라이언트 쪽에서 이루어 지므로 PHP로는 제어 할 수 없습니다. 할 수있는 일은 스타일/CSS를 전달하는 것뿐입니다. –