$str="Welcome to Plus2net.com PHP Section to learn about PHP built-in string functions";
echo wordwrap($str);
Output is here
Welcome to Plus2net.com PHP Section to learn about PHP built-in string functions
Syntax
wordwrap ( $input_string, int $width, string $break, bool $cut)
Parameter | DESCRIPTION |
---|---|
$input_string | Required : Input string |
$width | Optional : ( default : 75 ) The number of chars after which the string will be wrapped. |
$break | Optional : ( default '\n' ) To be used as line break. |
$cut | Optional : Boolean ( True or False ). TRUE : String is wrapped at or before the $width FALSE :( default ) String is wrapped after the word ( no split of word ) |
$str="Welcome to Plus2net.com PHP Section to learn about PHP built-in string functions";
echo nl2br(wordwrap($str));
Output is here
Welcome to Plus2net.com PHP Section to learn about PHP built-in string
functions
$str="Welcome to Plus2net.com PHP Section to learn about PHP built-in string functions";
echo wordwrap($str,20,'<br>');
Output is here
Welcome to
Plus2net.com PHP
Section to learn
about PHP built-in
string functions
$str="Welcome to Plus2net.com abcdefghijklmnopqrstuvwxyz";
echo wordwrap($str,20,'<BR>');
Output is here
Welcome to
Plus2net.com
abcdefghijklmnopqrstuvwxyz
Now let us make $cut = True
$str="Welcome to Plus2net.com abcdefghijklmnopqrstuvwxyz";
echo wordwrap($str,20,'<BR>',true);
Welcome to
Plus2net.com
abcdefghijklmnopqrst
uvwxyz
The long word ( more than 20 chars ) at the end is broken into a new line.