KenHorse Posted July 21, 2021 Share Posted July 21, 2021 (edited) $handle = fopen("/etc/rpt.fifo", "r") or die("Unable to open file!"); $buffer = trim(fgets($handle)); $ary = explode (",", $buffer); $x = $ary[2]; print $x; flush(); pclose($handle); When I run it, it reports: Notice: Undefined offset: 2 on line 4 This is the line in /etc/rpt.fifo that is being read (there are 4 indices) 20210721153256,1100,TXKEY,89790 The error makes no sense to me but I'm no expert <g> Edited July 21, 2021 by KenHorse Quote Link to comment https://forums.phpfreaks.com/topic/313410-i-dont-see-what-is-wrong-with-this-array-read/ Share on other sites More sharing options...
requinix Posted July 22, 2021 Share Posted July 22, 2021 1 hour ago, KenHorse said: This is the line in /etc/rpt.fifo that is being read (there are 4 indices) 20210721153256,1100,TXKEY,89790 That's great and all, but what is the value of $buffer? Quote Link to comment https://forums.phpfreaks.com/topic/313410-i-dont-see-what-is-wrong-with-this-array-read/#findComment-1588476 Share on other sites More sharing options...
KenHorse Posted July 22, 2021 Author Share Posted July 22, 2021 The line I posted is the contents of $buffer 20210721153256,1100,TXKEY,89790 Quote Link to comment https://forums.phpfreaks.com/topic/313410-i-dont-see-what-is-wrong-with-this-array-read/#findComment-1588477 Share on other sites More sharing options...
requinix Posted July 22, 2021 Share Posted July 22, 2021 https://3v4l.org/GH1pk If $buffer was what you say it was then it should all work fine. But it does not work fine. So $buffer must be something else. I know you think the contents of the file are that string, but have you checked literally what the value of $buffer is? Quote Link to comment https://forums.phpfreaks.com/topic/313410-i-dont-see-what-is-wrong-with-this-array-read/#findComment-1588480 Share on other sites More sharing options...
KenHorse Posted July 22, 2021 Author Share Posted July 22, 2021 Yes, I agree and that's why I'm here! It should work but it doesn't. and yes, I KNOW what's in $buffer as I if I place a print statement after the $buffer assignment, that line shows VERY frustrating, yes Quote Link to comment https://forums.phpfreaks.com/topic/313410-i-dont-see-what-is-wrong-with-this-array-read/#findComment-1588481 Share on other sites More sharing options...
kicken Posted July 22, 2021 Share Posted July 22, 2021 add var_dump($buffer, $ary); after your call to explode, maybe it'll shed some light on the situation? Is this code being called multiple times? Maybe the first time it has the data like you expect, but the second time $buffer is an empty string. Quote Link to comment https://forums.phpfreaks.com/topic/313410-i-dont-see-what-is-wrong-with-this-array-read/#findComment-1588483 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.