Page 1 of 1

Split string into parts, only after whole word

Posted: Fri Sep 17, 2010 8:38 am
by dimxasnewfrozen
I have a really long string that I'm sending to a pdf document. When I send the string over to the pdf document, it doesn't get formatted very well so I was wondering if I could split the string into pieces.

Current I'm using:

Code: Select all

$new_string = substr($string, 0, 100);
$new_string .= "\n" . substr($string, 100, 200);
This works for the most part however, it may split the string in the middle of word. Is there a way I can split the string after 100 or so words instead of characters?
Thanks

Re: Split string into parts, only after whole word

Posted: Fri Sep 17, 2010 10:37 am
by McInfo
PHP Manual: wordwrap() wrote:string wordwrap ( string $str [, int $width = 75 [, string $break = "\n" [, bool $cut = false ]]] )

Re: Split string into parts, only after whole word

Posted: Fri Sep 17, 2010 2:49 pm
by dimxasnewfrozen
Oh wow perfect. I didn't even know that function existed.