title: PHP Won't Match String - Encoding Issue?
body: <p><strong>I "solved" this myself: the text files must be encoded ANSI. But I don't know why, or why <code>filter_var()</code> didn't help, so I thought this would still be educational for myself and others.</strong></p>
  
  <p>I haven't learned databases yet so I've started my foray into templates / generated content for my photo gallery pulling info from txt files. I have <code>categories.txt</code>:</p>
  
  <pre><code>Architectural
  Fashion
  // etc
  </code></pre>
  
  <p>Then, within my template:</p>
  
  <pre><code>$Categories = file('shared/categories.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  $This_Page = filter_var($Categories[1], FILTER_SANITIZE_STRING);
  
  $Image_List = file('shared/'.$This_Page.'.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  
  foreach ($Categories as $c) {
      if ($c == $This_Page) {
          echo 'test successful!';
      }
      else {
          echo 'test failed';
      }
  }
  </code></pre>
  
  <p>This always works. However, if on line 2 I use <code>Categories[0]</code>:</p>
  
  <p>If <code>categories.txt</code> is encoded UTF-8, <code>shared/$This_Page.txt</code> can't be found and the <code>if</code> returns "test failed", and <code>var_dump()</code> finds <code>$This_Page</code> to be 3 characters longer than it should be. Even with <code>filter_var()</code>.</p>
  
  <p>Worse, if <code>categories.txt</code> is encoded Unicode, the code fails from the very first line with "file() expects parameter 1 to be a valid path."</p>
  
  <p>And only if <code>categories.txt</code> is encoded ANSI does it work correctly.</p>