Re: Splitting long text

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

 



I have been using the below function successfully. Hope it works for you.
-- Anas



// textwrap 1.1 Brian Moon <brian@xxxxxxxxxx>
// This code is part of the Phorum project <http://phorum.org>
// $String     The string to be wrapped.
// $breaksAt   How many characters each line should be.
// $breakStr   What character should be used to cause a break.
// $padStr     Allows for the wrapped lines to be padded at the begining.

function textwrap ($String, $breaksAt = 78, $breakStr = "\n", $padStr="")
{
   $newString="";
   $lines=explode($breakStr, $String);
   $cnt=count($lines);
   for($x=0;$x<$cnt;$x++){
       if(strlen($lines[$x])>$breaksAt){
           $str=$lines[$x];
           while(strlen($str)>$breaksAt){
               $pos=strrpos(chop(substr($str, 0, $breaksAt)), " ");
               if ($pos == false) {
                   break;
               }
               $newString.=$padStr.substr($str, 0, $pos).$breakStr;
               $str=trim(substr($str, $pos));
           }
           $newString.=$padStr.$str.$breakStr;
       }
       else{
           $newString.=$padStr.$lines[$x].$breakStr;
       }
   }
   return $newString;

} // end textwrap()







On 1/23/07, Skip Evans <skip@xxxxxxxxxxxxxxxxx> wrote:

Hey all,

I have a requirement to take a large amount of
text, a story submitted to a competition, and
split into displayable chunks of 600 words each.

I'd like some feedback on the best way to this.

Thanks!
Skip

--
Skip Evans
Big Sky Penguin, LLC
61 W Broadway
Butte, Montana 59701
406-782-2240
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=
Check out PHPenguin, a lightweight and
versatile PHP/MySQL development framework.
http://phpenguin.bigskypenguin.com/

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




--
Anas Mughal

[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