-1

I have this wonderful piece of code from here

But if some one edits the form through firebug or disable the js then this wont work, I want to have server side validation for this function, can anyone direct me to the right path please

Community
  • 1
  • 1
sammry
  • 412
  • 4
  • 16

1 Answers1

1

The following php code will give you the number of new lines in the text data:

echo substr_count(nl2br($textdata), '<br />') + 1;

the use of nl2br() is to support the different new lines formats (\r\n, \n\r, \n y \r)

Test:

$textdata = 'First line
second line
third line
fourth line';

$lines = substr_count(nl2br($textdata), '<br />') + 1;
echo $lines; //will output 4
Nelson
  • 49,283
  • 8
  • 68
  • 81
  • at the time of submitting the form, i need to validate the textarea input. For example, If a user has entered 10 lines data, then I need to accept else show the error output. Thanks for the info – sammry Oct 02 '12 at 12:40
  • But that is not server side validation!, you should do your server side validation on the PHP script receiving the form call, otherwise you are vulnerable. – Nelson Oct 02 '12 at 12:43
  • hmm, I understand. Thanks and appreciate your help – sammry Oct 02 '12 at 12:45