Author Topic: Counting lines  (Read 524 times)

0 Members and 1 Guest are viewing this topic.

Offline NLCJTopic starter

  • Enthusiast
  • Posts: 129
  • Gender: Male
    • View Profile
Counting lines
« on: September 09, 2010, 04:45:47 PM »
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

Offline PFMaBiSmAd

  • Guru
  • 'Mind Boggling!'
  • *
  • Posts: 15,191
  • In Coding, Automatic means you write code to do it
    • View Profile
Re: Counting lines
« Reply #1 on: September 09, 2010, 04:49:20 PM »
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?
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

Offline rwwd

  • Enthusiast
  • Posts: 425
  • Gender: Male
  • RTFM->then ask questions..
    • View Profile
Re: Counting lines
« Reply #2 on: September 09, 2010, 04:50:57 PM »
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

Offline NLCJTopic starter

  • Enthusiast
  • Posts: 129
  • Gender: Male
    • View Profile
Re: Counting lines
« Reply #3 on: September 09, 2010, 05:01:33 PM »
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. :)

Offline rwwd

  • Enthusiast
  • Posts: 425
  • Gender: Male
  • RTFM->then ask questions..
    • View Profile
Re: Counting lines
« Reply #4 on: September 09, 2010, 05:04:10 PM »
Cool. Have a nice cool beer now!

Rw