Jump to content

Counting lines


NLCJ

Recommended Posts

Hello,

I'm creating a program that analyzes information that is exported by another program. That program exports it in this way:

Value1 Value2 Value3 Value4

Value1 Value2...

 

In order to insert them in the database, I first have to know how many lines are inserted. They get send through HTML post. I already tried:

$lines = explode("\n", $string);
$number_lines = count($lines);

 

But this always results in 1. How do I fix this?

 

Regards,

Chris

Link to comment
https://forums.phpfreaks.com/topic/213004-counting-lines/
Share on other sites

There must not be any \n in the data.

 

Have you examined what is in $string or in $lines to see if they contain what you expect?

Yes, nothing. Just an enter.

Hi there,

 

If you are wanting a line counter, then this does the job for me:-

 

$lines = substr_count($comments, "\r\n") + 1;

 

This works just fine for me - hope it's what your after anyway.

 

Cheers,

Rw

Thanks a lot, this also does the job for me. :)

Link to comment
https://forums.phpfreaks.com/topic/213004-counting-lines/#findComment-1109362
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.