-1

Why down vote?, because I don't know where to start? I don't do this for a living like most here. If your going to down vote leave a message of at least why so maybe if I need to re-word it I can.

I don't have any code examples because I don't know were to even start this one.

I tried to search for a way to store and use/update a count in a session but nothing came up to help.

I have a pull-down that reads the option files and populates the second pull down based on what the choice was. That part works great.

With wanting to create this option file based on a different form submission(That is never the same) I'm having a problem.

Needing to get the file that looks like this 1st one to look like what's below as far as the line count and length goes. I was told the length count has to stay at the top of the list. There will be words and numbers only between the "".

This file is written from different points of the form submission so trying to add the proper line count as it's processed has been difficult.

Looking for something to either read and write or other simple ideas to control the line count during processing.

Thanks Bob

combo2.options.length = ;
combo2.options[] = new Option("Item1", "Item1");
combo2.options[] = new Option("Item2", "Item2");
combo2.options[] = new Option("Item3", "Item3");
combo2.options[] = new Option("Item4", "Item4");
combo2.options[] = new Option("", ""); etc...
combo2.options[] = new Option("", "");
combo2.options[] = new Option("", "");
combo2.options[] = new Option("", "");
combo2.options[] = new Option("", "");
combo2.options[] = new Option("", "");
combo2.options[] = new Option("", "");
combo2.options[] = new Option("", "");
combo2.options[] = new Option("", "");
combo2.options[] = new Option("", "");

To look like this

combo2.options.length = 14;
combo2.options[0] = new Option("Item1", "Item1");
combo2.options[1] = new Option("Item2", "Item2");
combo2.options[2] = new Option("Item3", "Item3");
combo2.options[3] = new Option("Item4", "Item4");
combo2.options[4] = new Option("", ""); etc....
combo2.options[5] = new Option("", "");
combo2.options[6] = new Option("", "");
combo2.options[7] = new Option("", "");
combo2.options[8] = new Option("", "");
combo2.options[9] = new Option("", "");
combo2.options[10] = new Option("", "");
combo2.options[11] = new Option("", "");
combo2.options[12] = new Option("", "");
combo2.options[13] = new Option("", "");
bpross
  • 363
  • 3
  • 11
  • 4
    I can only speak for myself, but I don't get what you are trying to accomplish. – TheWolf Aug 25 '14 at 19:41
  • Sorry, The site went down as I was posting and it didn't keep 1/2 of it. I was in the middle of updating. – bpross Aug 25 '14 at 19:43
  • @bpross Just ignore the hurried downvoters. Take your time, edit as much as you need and if it's a good question the upvotes will outweigh the downvotes. – kojiro Aug 25 '14 at 19:59

1 Answers1

1

You code looks like JavaScript, but you've posted this in PHP?

To get the number of lines in a string in PHP:

$str = ''; # your string
$lines = preg_split( '/\n|\r/', $str );
$no = count( $lines ); 
echo $no;

JS:

http://stackoverflow.com/questions/8488729/how-to-count-the-number-of-lines-of-a-string-in-javascript
Kohjah Breese
  • 4,008
  • 6
  • 32
  • 48
  • I posted it in php because a php form submission writes what's above and then is read by another page with the Java routine. I also asked to get help how to write the needed length and numbers [0] etc.. – bpross Aug 25 '14 at 20:07
  • Likewise. I am a bit lost as to what you want to do. The above solution should do what your title asks in PHP. But your post body and comment has confused me as to your intent. – Kohjah Breese Aug 25 '14 at 20:10
  • The top is what I can get printed into an option file. The second is what I'm trying to get it to look like. I can't get the numbers in the right order with fopen, fwrite because they are written at different times during the form process. Does it matter if they are all mixed around?, I was told they have to be in this order and the length at the top. – bpross Aug 25 '14 at 20:13
  • What is the source data? What does it look like? – Kohjah Breese Aug 25 '14 at 20:16
  • I added a few things to give a little better idea or I'm missing what data your talking about. – bpross Aug 25 '14 at 20:22
  • I found a way to store the count needed in a session. Thanks for all your help. – bpross Aug 25 '14 at 20:44