wordrap php
Today we will see how to break a sentance after some characters using php.
Sometime we need to break a long line into small peaces of sentence to meet the designing requirement. PHP has very good function wordwrap() to meet the req.
Basic sentance of the wordwrap() php function
string wordwrap ( string $str [, int $width = 75 [, string $break = "\n" [, bool $cut = false ]]] )
So u can see by default, wordwrap() uses a column width of 75 characters. This means that no line will be more than 75 characters long.
Wrapping very long words
For example suppose we have a sentance:
$sentance = ‘JohnCleese: Have you signed up to my monthly email yet? Youre missing outif you havent http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.co.uk/‘;
echo "<pre>" . wordwrap( $sentance, 10 ) . "</pre>";
output will be:
JohnCleese: Have you signed up to my monthly email yet? Youre missing outif you havent! http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.co.uk/
So you can see the problem at last sentence.
To make this work perfectly use the sentence like this
<?$sentance = 'JohnCleese: Have you signed up to my monthly email yet? Youre missing outif you havent! http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.co.uk/';echo "<pre>" . wordwrap( $sentance, 10, "\n", true ) . "</pre>";?>
Output will be like:
JohnCleese
: Have you
signed up
to my
monthly
email yet?
Youre
missing
outif you
havent!
http://aaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaa.c
o.uk/
So clear now.
Thanks
mrphpguru
http://www.mrphpguru.com






