PHP/String/wordwrap
Содержание
- 1 string wordwrap ( string str [, int line_length[, string break_char [, bool cut]]] )
- 2 string wordwrap ( string str [, int width [, string break [, bool cut]]] )
- 3 Supply 1 as a fourth parameter, which enables "cut" modewords over the limit will be cut up if this is enabled.
- 4 wordwrap() doesn"t break at your line limit if a word has more characters than the limit.
- 5 wordwrap() has two more optional arguments: a number representing the maximum number of characters per line and a string representing the end of the line string.
- 6 wordwrap() requires one argument, the string to be transformed.
- 7 Wrapping Text
string wordwrap ( string str [, int line_length[, string break_char [, bool cut]]] )
<source lang="html4strict">
$text = "this is a test. this is a test. this is a test. this is a test. this is a test. this is a test. this is a test.";
$text = wordwrap($text, 20, "
"); print $text; </source>
string wordwrap ( string str [, int width [, string break [, bool cut]]] )
<source lang="html4strict">
<?php
$textblock = "this is a test. this is a test. this is a test. this is a test";
echo wordwrap ($textblock, 20, "
");
?>
</source>
Supply 1 as a fourth parameter, which enables "cut" modewords over the limit will be cut up if this is enabled.
<source lang="html4strict">
<?
$text = "this is a test.this is a test.this is a test.this is a test.this is a test.this is a test."; $text = wordwrap($text, 6, "\n", 1); print $text;
?>
</source>
wordwrap() doesn"t break at your line limit if a word has more characters than the limit.
<source lang="html4strict">
<?php
$string = "this is a test. this is a test.this is a test.this is a test.this is a test.";
$string .= "this is a test.this is a test.this is a test.this is a test.this is a test.!";
print wordwrap( $string, 24, "
\n", 1 );
?>
</source>
wordwrap() has two more optional arguments: a number representing the maximum number of characters per line and a string representing the end of the line string.
<source lang="html4strict">
<?php
print wordwrap( $string, 24, "
\n");
?>
</source>
wordwrap() requires one argument, the string to be transformed.
<source lang="html4strict">
By default, wordwrap() wraps lines every 75 characters and uses \n as its line-break character.
<?php $string = "this is a test.this is a test.this is a test.this is a test.this is a test.this is a test."; $string .= "this is a test.this is a test.this is a test.this is a test.this is a test.this is a test."; print wordwrap($string); ?>
</source>
Wrapping Text
<source lang="html4strict">
<?php
$astring = "Hello\nWorld\n\nHow are you?"; echo nl2br ($astring) . "
"; $textblock = "this is a test. this is a test. this is a test. this is a test. this is a test. !"; echo wordwrap ($textblock, 20, "
");
?>
</source>