Split string into parts, only after whole word

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dimxasnewfrozen
Forum Commoner
Posts: 84
Joined: Fri Oct 30, 2009 1:21 pm

Split string into parts, only after whole word

Post 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
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Split string into parts, only after whole word

Post by McInfo »

PHP Manual: wordwrap() wrote:string wordwrap ( string $str [, int $width = 75 [, string $break = "\n" [, bool $cut = false ]]] )
dimxasnewfrozen
Forum Commoner
Posts: 84
Joined: Fri Oct 30, 2009 1:21 pm

Re: Split string into parts, only after whole word

Post by dimxasnewfrozen »

Oh wow perfect. I didn't even know that function existed.
Post Reply