0

how can i set charset to UTF-8 on a file created by php? i create my file like this:

if(!file_exists("games/".strtolower($dir)."/index.php")) {
        $create_index = fopen("games/".strtolower($dir)."/index.php", "w");
        $name = $row['name'];
        $content  = mb_convert_encoding($content,'UTF-8');
        $string = "
        <?php
        include '../../config.php';
        include('../../default_theme.php');
        setTitle(\"".$name."\");
        show(\"".$name."\");
        ";
        fwrite($create_index, $content);
        fwrite($create_index, $string);
        fclose($create_index);
    }

but then ä, ö and ü are displayed as ?�

thanks for ur help

  • 1
    http://stackoverflow.com/questions/4839402/how-to-write-file-in-utf-8-format – ka_lin Jul 09 '14 at 09:51
  • doesn't work, because in my created file i do a mysql query: $query = mysqli_query($db, "SELECT * FROM forum_categorys WHERE owner = '$cur_id'"); while($row = mysqli_fetch_assoc($query)) { echo '
  • '.$row["name"].'

    '.$row["description"].'
  • '; } and there are all ü,ä,ü displayed as ? – user3759502 Jul 09 '14 at 09:55
  • Are you displaying it as HTML? – Artur Kedzior Jul 09 '14 at 10:04
  • no, im displaying it with php as echo 'äüö'; @R2D2 – user3759502 Jul 09 '14 at 10:47
  • There are no non-latin characters in your PHP or SQL query code. Do you mean that the characters show incorrectly when displayed on your web page after being retrieved from your database? – timclutton Jul 09 '14 at 11:20
  • Please edit your question to show the values of `$row['name']` and `$content` before they are used in your code snippet above. – timclutton Jul 09 '14 at 11:28
  • i insert following line: mysqli_query($db, "SET NAMES utf8"); and it worked for me :D – user3759502 Jul 09 '14 at 12:45