title: PHP - How to write a line in text file if line already available in file then count the request
body: <p>I want to write a PHP code which write a string line in text file if the line already available in text file then count the requests for example
  text file contain:</p>
  
  <pre><code>red.apple:1
  big.orange:1
  green.banana:1
  </code></pre>
  
  <p>If some one request to add big.orange in file if its already available in file then count as <code>big.orange:2</code> if not available then write new line <code>big.orange:1</code> </p>
  
  <p>after execution code text file</p>
  
  <pre><code>    red.apple:1
      big.orange:2
      green.banana:1
  </code></pre>
  
  <p>I've written the following code but not working.</p>
  
  <pre><code>&lt;?PHP
  $name = $_GET['fname']
  
  $file = fopen('request.txt', "r+") or die("Unable to open file!");
  
  if ($file) {
      while (!feof($file)) {
          $entry_array = explode(":",fgets($file));
          if ($entry_array[0] == $name) {
              $entry_array[1]==$entry_array[1]+1;
              fwrite($file, $entry_array[1]);
          }
      }
      fclose($file);
  }    
  else{
      fwrite($file, $name.":1"."\n");
      fclose($file);
  }
  ?&gt;
  </code></pre>