Drop Text Down a Line after so many characters

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
jasonfarrell
Forum Newbie
Posts: 3
Joined: Fri Jan 23, 2004 5:09 pm

Drop Text Down a Line after so many characters

Post by jasonfarrell »

I need to set a maximum line length of a string. For example if the string is "Testing Test Tester Test" and I want only 5 characters per string, it needs to knock the next line down. I also need it to keep words together if it's under the 5 characters possible. So it would be:
"Testi
ng
Test
Teste
r
Test"

I'm using imagettftext() to create a box of text over a graphic, but there has to be a limit to how long each line of text is, and I just can't figure this out.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

wordwrap() which gives you the option to choose your line cutter (defaults to \n, so you're good with the default) and the option to keep whole words.

also str_split() (php >= 5) and some nifty checks for whole words (checking for spaces)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply