PHP wordwrap() 함수
예시
문자열이 특정 길이에 도달하면 새 줄로 줄바꿈합니다.
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n");
?>
정의 및 사용
wordwrap() 함수는 문자열이 특정 길이에 도달하면 새 줄로 줄바꿈합니다.
참고: 이 함수는 줄 시작 부분에 공백을 남길 수 있습니다.
통사론
wordwrap(string,width,break,cut)
매개변수 값
Parameter | Description |
---|---|
string | Required. Specifies the string to break up into lines |
width | Optional. Specifies the maximum line width. Default is 75 |
break | Optional. Specifies the characters to use as break. Default is "\n" |
cut |
Optional. Specifies whether words longer than the specified width should be wrapped:
|
기술적 세부 사항
반환 값: | 성공하면 줄로 쪼개진 문자열을 반환하고 실패하면 FALSE를 반환합니다. |
---|---|
PHP 버전: | 4.0.2+ |
변경 로그: | PHP 4.0.3에 cut 매개변수가 추가되었습니다 . |
더 많은 예
예시
모든 매개변수 사용:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n",TRUE);
?>
예시
문자열을 새 줄로 줄바꿈:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15);
?>
위 코드의 HTML 출력은 (소스 보기):
<!DOCTYPE html>
<html>
<body>
An example of a
long word is:
Supercalifragulistic
</body>
</html>
위 코드의 브라우저 출력은 다음과 같습니다.
An example of a long word is: Supercalifragulistic
❮ PHP 문자열 참조