title: PHP Counting delimited values in text file that are all on the same line
body: <p>I need a script to count the number of pipe delmited entries in a text file that are all on one line. I found a script that counts lines and modified it thinking I might get it to work but sadly it still counts the lines, so at present putputs the value 1. Please can you have a look and help me with a solution? The text file looks something like this:</p>
  
  <pre><code>Fred|Keith|Steve|James
  </code></pre>
  
  <p>The script I was trying is this:</p>
  
  <pre><code>$file1 = "names.txt";
  $line = file($file1); 
  $count = count(explode("|", $line));
  echo "$file1 contains $count words";
  </code></pre>
  
  <p>Any assistance much appreciated.
  Many thanks.</p>