[Forms] Limit lines instead of characters (updated problem!)

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
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

[Forms] Limit lines instead of characters (updated problem!)

Post by thiscatis »

Hi!

Is there a way that you can limit the number of lines of text submitted through a form instead of the characters?

(no javascript pls)
Last edited by thiscatis on Tue Aug 01, 2006 10:55 am, edited 1 time in total.
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Post by litebearer »

Hmmm

I suppose you could check the variable for the number of new lines and either send back to user to re-enter or simply truncate the variable to three lines.

w/o javascript this would need to be done server-side (not sure how ajax works but it may be possible to us eit also)

Lite...
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

see:

Code: Select all

count_chars();
wordwrap();
explode() and count();
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

ole wrote:see:

Code: Select all

count_chars();
wordwrap();
explode() and count();
could you be more precise?

The problem:
The input is done bya wysiwyg editor, when you hit enter it's gives <p align = left> text </p> as a new line.
This messes up my layout.
I already tried to do it with


Code: Select all

$text = substr($contenta,0,250);
$text = ereg_replace( "<p align="left">", " ", $text);
$text = ereg_replace( "</p>", "<br>", $text);
but it looks like it won't count spaces as a character..

anyone?
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

maybe another solution:
Is there a way to limit the rows of an textarea?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

try

Code: Select all

$text = substr($contenta, 0, 250);
$text = str_replace('<p align="left">', '', $text);
$text = str_replace('</p>', '<br /><br />', $text);
Post Reply