Jump to content

Recommended Posts

I am not sure why this is happening, but any help would be greatly appreciated. I am really a novice, but I cannot figure out why the code $str_begin = strpos($s, $parameters[$worker]); is not working. What I am trying to do is to go through a file, pick out the $parameters variable with the additional information then store it in the array $parametervalue[$worker]. When I run the code I cannot get $str_begin to return anything . Please help :confused:

 

  <?php
   $handle = fopen("filename", "r");
  $parametervalue = array();

                       $parameters = array(
                                        'scannerId', 
                                        'hour', 
                                        'minute', 
                                        'second', 
                                        'millisec');
                        
                        while (! feof($handle))
                        {
                       $worker = 0;
                       while ($worker < count($parameters)) {

                            $s = rtrim(fgets($handle),"\r\n");
                            $findme = $parameters[$worker];
                            
                            if (strpos($s,$parameters[$worker]) !== FALSE)
                            {
                                $str_begin = strpos($s, $parameters[$worker]);
                                $str_end = strpos($s,",");
                                $str_len = $str_end - $str_begin;
                                $parametervalue[$worker] = substr($s,$str_begin,$str_len);
                            } else {
                                $parametervalue[$worker] = "";
                            }
                        $worker++;
                       }
                    }
   ?> 

Yes, That is what I want to do. I want to take a line and then look for all of the "workers" in that line. The reason that I am doing it that way is because the files are tens of thousands of lines long and creates problems. Any idea on what is wrong though?

Ok, so I figured out what I was doing wrong. I guess as with a lot of this stuff I was making a dumb mistake. I had the $s variable assignment in the loop so it was changing all the time. That is what was throwing off the logic in the loop.  :anim_rules::facewall:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.