Re: Splitting long text
| From: | Anas Mughal | Date: | Wed, 24 Jan 2007 03:20:52 +0000 |
| Subject: | Re: Splitting long text | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247663@lists.php.net to get a copy of this message | ||
I have been using the below function successfully. Hope it works for you.
-- Anas
// textwrap 1.1 Brian Moon <brian@phorum.org>
// 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@bigskypenguin.com> 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