RE: Breaking a line in two

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You might want to consider wordwrap(), which will count out to the length
you specify.
If the next character is not a blank, it will back up to the first available
blank and insert the break character you choose at that point (inplace of
the blank), "<br>" is a valid option, and it will continue doing this until
the line is broken up into as many lines as it takes that are never longer
than the number specified.  If you want to divide it in half divide strlen()
by two.

Wordwrap would work like you specify, if you use 15 as the max length,
except that it would not leave the blank at the end of the line (can't
imagine why you'd want that).  Also since you goal is to limit the size of a
line, not sure why you'd want have it add to the length looking for the
blank, suppose the word at character position 10 (in your case) was
"supercallifragilisticexprealidoceous", do you really want your line to be
46 characters long because a long word was placed at the break point?

Hth,

Warren Vail

> -----Original Message-----
> From: Ron Piggott [mailto:ron.php@xxxxxxxxxxxxxxxxxx] 
> Sent: Sunday, August 17, 2008 3:11 PM
> To: PHP General
> Subject:  Breaking a line in two
> 
> 
> Is there a way to add 
> 
> <br>
> 
> midway through a string, following the first available space?
> 
> Example:
> 
> The cat jumped up high.
> 
> This is 23 characters long.  I want <br> added after the 12th 
> character, following the first space:
> 
> The cat jumped <br>up high.
> 
> would be the desired output.
> 
> Ron
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/) To 
> unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux