telman28 Posted June 11, 2012 Share Posted June 11, 2012 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 <?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++; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/264019-issue-using-strpos-with-an-array-variable/ Share on other sites More sharing options...
requinix Posted June 11, 2012 Share Posted June 11, 2012 You do understand that for every worker you try to read a new line from the file? It's not that you're reading a file and then checking it for all the workers? Quote Link to comment https://forums.phpfreaks.com/topic/264019-issue-using-strpos-with-an-array-variable/#findComment-1353046 Share on other sites More sharing options...
telman28 Posted June 12, 2012 Author Share Posted June 12, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/264019-issue-using-strpos-with-an-array-variable/#findComment-1353124 Share on other sites More sharing options...
telman28 Posted June 12, 2012 Author Share Posted June 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/264019-issue-using-strpos-with-an-array-variable/#findComment-1353130 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.