this is wrong: > foreach ($lines as $line) { > if (strlen($line) > $maxchars) { > $newtext .= substr($line, 0, $maxchars)."\n"; > $newtext .= substr($line, $maxchars)."\n"; > } > }
try this: foreach ($lines as $line) { if (strlen($line) > $maxchars) { $newtext .= substr($line, 0, $maxchars)."\n"; $newtext .= substr($line, $maxchars)."\n"; } else { $newtext .= $line."\n"; } } Regards Michael "Michael Virnstein" <[EMAIL PROTECTED]> schrieb im Newsbeitrag [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > if you want to write into the database, i wouldn't convert newline to <br>. > do this > when you read from the database using nl2br($var) ot convert every newline > in $var to <br>. > default <br> after 75 characters if no <br> was found before. > if you don't care about word-splitting, you could do the following: > > //INSERT TO DATABASE > //max number of chars per line > $maxchars = 75; > //lets say $var is the content of your textarea > $lines = explode("\n", $var); > > // text we want to write to the db > $newtext = ""; > > foreach ($lines as $line) { > if (strlen($line) > $maxchars) { > $newtext .= substr($line, 0, $maxchars)."\n"; > $newtext .= substr($line, $maxchars)."\n"; > } > } > > > // SELECT FROM DATABASE > > //lets say $var is the selected content > echo nl2br($var); > > This is very simple solution. It won't look for words and splits after the > word > and if your line is 76 chars long, it'll convert it into two lines, onw with > 75 chars > and one with 1 char. but it's a start i think. > > Regards Michael > > > > > "R" <[EMAIL PROTECTED]> schrieb im Newsbeitrag > 000b01c1ed6e$d21595e0$0a6da8c0@lgwezec83s94bn">news:000b01c1ed6e$d21595e0$0a6da8c0@lgwezec83s94bn... > > Greetings All, > > (Special greetings go out to Steve for excellient previous help - Thanks > > again dude) > > Calling all PHP gurus, have broked my head over this but cant seem to > figure > > this out in c,perl or java servlets. > > Am new to PHP so dont even know the common functions leave alone the > answer > > to this problem. > > Heres the setup: > > I have a form with just one TEXTAREA > > Data from this form is entered directly into the database > > > > BUT... > > > > everytime a user presses the ENTER or RETURN key on the keyboard, when the > > PHP script validates the form > > I want it to add <br> it should also add a <br> if the line is > sayyyyy....75 > > charactors long & if there is no <br> or enter key pressed.. > > If it finds any " it should convert it to ' > > > > Any ideas? > > > > Any help appreciated. > > Have a great day. > > -Ryan A. > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php