Need to know how many lines in a string.
"frnejkgv]
rfgdrf
fdgfd
fdgdf" = 6
"vfv
fdb
bfd" = 4
Thanks
Printable View
Need to know how many lines in a string.
"frnejkgv]
rfgdrf
fdgfd
fdgdf" = 6
"vfv
fdb
bfd" = 4
Thanks
PHP Code:$line = split("\\n", $input_several_lines_long);
echo count($line)
HTH
P.S. - Just so you know, I don't really know PHP, but when you ask questions, I look under http://www.php.net , and tend to find answers pretty quickly. :thumb:
Might be a little quicker for you than posting on here :)
\\n won't work, that will give you backslash n not a newline character.
PHP Code:$lineCount = substr_count($string, "\n");
Quote:
Originally Posted by penagate
Hmm, on the page I was reading, someone posted that it requires \\n, not \n...
Ill see if I can find the post..Maybe there was a certain circumstance for it
*edit* Found the post, looks like its supposed to be /\n instead of \\n :blush:
Quote:
Originally Posted by http://ca3.php.net/manual/en/function.split.php#49130
FYI, if you use single quotes the escape sequences are turned off. It's always better to use single quoted string literals if you can as the overheads of parsing the string for variables/escape sequences are removed.
Edit: I really have no idea why you'd want to use /\n. It makes no sense.
If it is a windows file you will need to use the DOS CRLF sequence - "\r\n"
The number of \n's will always match the \r's in that case.
Indeed :confused:Quote:
Originally Posted by penagate
/pretends to understand