braking long line

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
yoha
Forum Newbie
Posts: 2
Joined: Tue Sep 13, 2005 2:05 pm

braking long line

Post by yoha »

hey.. my question is pretty simple..
i have user input for some text
what i want to do? for example when i have 10 chars in a line it will go down and will not ruin my page :)

not
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
but
"aaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaa"


sorry about my bad english :)
thanks
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Use http://www.php.net/wordwrap().

Kind of like this:

Code: Select all

$user_input = '123456789012345678901234567890';
$broken_up_user_input = wordwrap($user_input,10,'<br />',1);
For wordwrap(), the first argument is what the user entered, the second argument is the width you want the string to be, the third argument is what to use as the newline character, and the last character tells wordwrap to cut the word at 10 characters.

Echoing $broken_up_user_input will give you this:

Code: Select all

1234567890<br />1234567890<br />1234567890
jcart | fixed parse error
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
yoha
Forum Newbie
Posts: 2
Joined: Tue Sep 13, 2005 2:05 pm

Post by yoha »

thanks :!:
Post Reply