title: Run while in PHP
body: <p>Im not a PHP programmer but for me to get the job done, I did a few researches and I was able to achieve my goal... well partially</p>
  
  <p>What the program does is: 
  It reads a txt file that has a content like this:</p>
  
  <p>Dishwasher is finished and ready. Jun 22, 2016 - 9:15 PM</p>
  
  <p>Front door is been opened. Jun 22, 2016 - 8:39 PM</p>
  
  <p>Front door is been opened. Jun 22, 2016 - 9:55 AM</p>
  
  <p>So what I tried to do is to change the time and date for " 33 minutes ago" " 2 days ago" for each line and process one by one to display as echo on the page.</p>
  
  <p>So I had to create something like this:</p>
  
  <p>$first_part = The text in the beginning example "Dishwasher is finished and ready."</p>
  
  <p>$second_part = The text in between the code "Jun 22, 2016 - 9:15 PM" and convert this to "10 minutes ago" or whatever time is... </p>
  
  <p>Then join those two variables as one and display in echo.</p>
  
  <p>But I need to run all of this again for the first 2 lines, not the whole file.</p>
  
  <p>So the code I have its working PERFECT if its only one time, but if I put the while command, the page displays blank.
  So if I can get a help just to get the while on this whole process to work, it would be appreciated. Thank you very much! </p>
  
  <p>Here is my code:
  <pre><code>
      $monthyr = date('Ym');
      $filename = $monthyr . "_notification" . ".txt"; //Every month the filename      changes to YYYYmm_notification.txt//
      $file = fopen($filename,"r");
      $content = fgets($file);
      $i = 1;</p>
  
  while($i &lt;= 2)     //Here where the problem is, when I use this string//
  {
  
  $string = $content;
  $substring = substr($string, 0, strpos($string, "&lt;"));
  
  
  function get_string_between($string, $start, $end){
      $string = ' ' . $string;
      $ini = strpos($string, $start);
      if ($ini == 0) return '';
      $ini += strlen($start);
      $len = strpos($string, $end, $ini) - $ini;
      return substr($string, $ini, $len);
      }
  
  $fullstring = $content;
  $parsed = get_string_between($fullstring, '&lt;div id="time"&gt;', '&lt;/div&gt;');
  
  
  
  $time = strtotime($parsed);
  
  $ago = humanTiming($time).' ago';
  function humanTiming ($time)
  {
  
      $time = time() - $time; // to get the time since that moment
      $time = ($time&lt;1)? 1 : $time;
      $tokens = array (
          31536000 =&gt; 'year',
          2592000 =&gt; 'month',
          604800 =&gt; 'week',
          86400 =&gt; 'day',
          3600 =&gt; 'hour',
          60 =&gt; 'minute',
          1 =&gt; 'second'
  );
  
  foreach ($tokens as $unit =&gt; $text) {
      if ($time &lt; $unit) continue;
      $numberOfUnits = floor($time / $unit);
      return $numberOfUnits.' '.$text.(($numberOfUnits&gt;1)?'s':'');
  }
  
  }
  echo " " . $substring  . $ago . "&lt;br /&gt;";
  
  $i++;
  }
  
  fclose($file); 
  &lt;/pre&gt;&lt;/code&gt;
  </code></pre>