title: PHP: check if empty line ("\n")
body: <p>I'm using an API in order to retrieve some temperature and location values in JSON format.
  I'm writing the output in a plain text cachefile. </p>
  
  <p>However a temperature station may fail reporting the temperature value, and in that case my output will be an empty line (\n). I want to handle such case by displaying "N/A" for a non-reporting station.</p>
  
  <p>Here's a typical cachefile with the first station reporting temperature and location, and the second station shut down (reporting two empty lines):</p>
  
  <pre><code>27.6
  Napoli-Posillipo
  (an empty line)
  (an empty line)
  </code></pre>
  
  <p>I tried with:</p>
  
  <pre><code>$display = file($cachename);
  $temperature[0] = $display[0];
  $location[0] = $display[1];
  $temperature[1] = $display[2];
  $location[1] = $display[3];
  
  $temp_avg = (($temperature[0]+$temperature[1])/2); //average temperature
  
  if($temperature[0] = "\n"){ //if weather station is not reporting data
     $temperature[0] = "N/A";
     $temp_avg = "N/A";
  }
  
  if($temperature[1] = "\n"){
     $temperature[1] = "N/A";
     $temp_avg = "N/A";
  }
  
  
  echo "&lt;div id='temperature'&gt;&lt;b&gt;".$temperature[0]."&lt;/b&gt;°C (".$location[0].") | ";
  echo "&lt;b&gt;".$temperature[1]."&lt;/b&gt;°C (".$location[1].") | ";
  echo "&lt;b&gt;".$temp_avg."&lt;/b&gt;°C (avg) | ".$minutes."m".$secondsleft."s ago&lt;/div&gt;";
  </code></pre>
  
  <p>However I keep getting "N/A" for both stations, even if the first station correctly reports its temperature value.</p>
  
  <blockquote>
    <p>N/A°C (Napoli-Posillipo ) | N/A°C () | N/A°C (avg) | 12m21s ago</p>
  </blockquote>
  
  <p>I tried with fgets() instead of file(), but I got an error:</p>
  
  <blockquote>
    <p>fgets() expects parameter 1 to be resource, string given in [...] on
    line 54</p>
  </blockquote>
  
  <p>I also tried using <em>if(empty($temperature[foo]))</em> but it didn't work, because of course <em>\n != empty</em>.</p>
  
  <p>Any hints?
  Thanks in advance</p>