title: PHP glob directory UTF-8
body: <p>I am trying to get all files within a variable path ... atm I am using glob(), but I just can not find a way to open a path which contains ä ü ö in it...</p>
  
  <p>I have tried a lot of de/encoding, but none seem to work...
  When I change the ä ü ö in the filename and the variable I get the right answer... so it has to be smth with utf8 chars...I guess</p>
  
  <p><strong>PHP script</strong></p>
  
  <pre><code>// Get the variable via an Ajax post
  
  $town =$_POST['town'];       // For example "Bankdrücken"
  
  $pfad = 'maps/'. $country.'/'. $town .'/*.jpg';
  
  $files = glob($pfad);
  $n_files = count($files);
  
      $erg = new stdClass();
      $erg-&gt;files = $files;
      $erg-&gt;n_files = $n_files;
  
      echo json_encode($erg);
      return;
  </code></pre>
  
  <p><strong>JavaScript</strong></p>
  
  <pre><code>.success(function(data){
      console.log(data);
  ...
  </code></pre>
  
  <p>This will not return .../Bankdrücken, but .../Bankdr\u00fccken</p>
  
  <p>When I do jQuery.parseJson(data); it returns ./Bankdrücken, but as this is on the client side the server side already did fail .. I just can't get it right.</p>
  
  <p>Here is a real example ... if the $variable within the file path contains ä ö ü -> glob() will not get me any files...
  // No, I am printing out what I get back from the Ajax call...</p>
  
  <p>Trial One (with ü):</p>
  
  <p>"stdClass Object
  (
      [files] => Array
          (
          )</p>
  
  <pre><code>[n_files] =&gt; 0
  [filename] =&gt; workout_uebungen/Brust/Liegestützen/
  </code></pre>
  
  <p>)
  "
  /******************************************/
  Trail two (I changed the file name from Liegestützen => Liegestuetzen and the $var from Liegestützen => Liegestuetzen)</p>
  
  <p>"stdClass Object
  (
      [files] => Array
          (
              [0] => workout_uebungen/Brust/Liegestuetzen/1.jpg
              [1] => workout_uebungen/Brust/Liegestuetzen/2.jpg
          )</p>
  
  <pre><code>[n_files] =&gt; 2
  [filename] =&gt; workout_uebungen/Brust/Liegestuetzen/
  </code></pre>
  
  <p>)
  "</p>
  
  <p>So trial 2 gives the right answer, but I don't want to change all my files ... as well it would be a dirty solution to me...</p>