php - string not splitting using explode -


i trying split string below on <br> reason loop returns 1 giant string. swear im missing simple cant see it. thanks!

if(file_exists("/home/pi/desktop/picontrol/status_log"))     {         $file = readfile("/home/pi/desktop/picontrol/status_log");         $arr= explode("<br>",$file);         //$file=array_slice($file,count($file)-5);         //$file=array_reverse($file);         foreach($arr $f)         {             echo $f;             echo "woo";         }            fclose($file);     }     else     {         echo "no file found";     } 

contents of file:

<br>light now: on 2015-06-01 03:32:42.902387<br>light now: off 2015-06-01 03:32:54.360173<br>light now: on 2015-06-01 03:33:07.781693<br>light now: off 2015-06-01 03:33:15.867386<br>light now: on 2015-06-01 03:34:42.683736<br>light now: off 2015-06-01 03:34:45.205557<br>light now: on 2015-06-01 03:36:18.037309<br>light now: off 2015-06-01 03:36:25.915424<br>light now: on 2015-06-01 03:36:58.261714<br>light now: off 2015-06-01 03:37:05.103494<br>light now: on 2015-06-01 11:00:01.735592<br>light now: off 2015-06-01 13:06:50.254778<br>light now: on 2015-06-01 17:28:11.218417 

should return:

light now: on 2015-06-01 03:32:42.902387 woo light now: off 2015-06-01 03:32:54.360173 woo ..... 

readfile() doesn't return file can read in manual:

returns number of bytes read file. if error occurs, false returned , unless function called @readfile(), error message printed.

i think want this:

if(file_exists("/home/pi/desktop/picontrol/status_log")) {      $lines = explode("<br>", file_get_contents("/home/pi/desktop/picontrol/status_log"));      foreach($lines $line) {         echo $line . "<br>";         echo "woo<br>";     }   } else {     echo "no file found"; } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -