title: PHP Read txt file line by line
body: <p>I have this PHP code:</p>
  
  <pre><code>$myfile = fopen("index.txt", "r") or die("Unable to open file!");
  
  //rewind($myfile);
  fseek($myfile, 0);
  
  while(!feof($myfile)) {
      $line=fgets($myfile);
      echo $line;
      echo strpos($line,":");
      echo "&lt;br /&gt;";
  }
  
  fclose($myfile);
  </code></pre>
  
  <p><strong>index.txt</strong> contains the following data:</p>
  
  <pre class="lang-none prettyprint-override"><code>:a
  1:b
  2:c
  </code></pre>
  
  <p><strong>result:</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>:a 3
  1:b 1
  2:c1
  </code></pre>
  
  <p>I'm having problem with the function <code>strops</code>, it doesn't give the accurate position number.</p>
  
  <p>As you can see in the result, I get the number <code>3</code> while it should be <code>0</code>
  and there is a white space added between the letter <code>a</code> &amp; the number <code>3</code> (and between the letter <code>b</code> &amp; the number <code>1</code>).  Why is that?</p>
  
  <p>As you can see above, I tried to set the file pointer position to 0, but didn't work.</p>
  
  <p>Thanks.</p>