Please help with xml encoding in utf-8 (russian languge problem)

nnnswordfish

Новичок
Please help with xml encoding in utf-8 (russian languge problem)

please help me with this php code try many thing but nothing :(

ok here is php script wich scan mp3/russian dir on server and creates list files and folders in xml but in encoding ANSI,please help to modifi it to create xml file in utf-8 encodin here is my script



PHP:
<?php

    // 
    function getDirectory( $path = '.', $level = 1 ){
        // Directories to ignore when listing output. Many hosts
        // will deny PHP access to the cgi-bin.
        $ignore = array( 'cgi-bin', '.', '..', "_notes" );
        // File extensions to ignore
        $exts = array( '.db', '.ini' );

        // Open the directory to the handle $dh
        $dh = @opendir( $path );

        // Loop through the directory
        while( false !== ( $file = readdir( $dh ) ) ){

           // Check that this file is not to be ignored
           if( !in_array( $file, $ignore ) && !in_array( strtolower( strrchr( $file, '.' ) ), $exts ) ) {

              // Just to add spacing to the list, to better show the directory tree.
              $spaces = str_repeat( ' ', ( $level * 5 ) );

              // Its a directory, so we need to keep reading down...
              if( is_dir( "$path/$file" ) ){
                 $x.= $spaces . "<artist label=\"$file\" >\n";
                 // Re-call this same function but on a new directory.
                 // this is what makes function recursive.
                 $x.= getDirectory( "$path/$file", ($level+1) );
                 $x.= $spaces . "</artist>\n";

              } else {

                 // Just print out the filename
                 $x.= $spaces . "<song url=\"$path/$file\" label=\"" . $file . "\" />\n";

              }

           }

        }

        closedir( $dh );
        // Close the directory handle
       return $x;

    }

    $dir = "mp3/russian";

    $v= "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
    $v.= "<music>\n";
    // Get the current directory
    $v.= getDirectory($dir);
    $v.= "</music>" ;


    $filename = "mp3russian.xml";

        if (is_writable($filename)) {
            if (!$handle = fopen($filename, 'w')) {
                exit;
            }

            if (fwrite($handle, $v) === false) {
                exit;
            }
            fclose($handle);
        }else echo "Can not edit the file";

?>


i try like this but nothing aded header

header('content-type: text/html; charset:Utf-8');





Please help me :)
 

Mr_Max

Первый класс. Зимние каникулы ^_^
Команда форума
1. Don't scan russian directory for create mp3 file list.
2. УЧИ РУССКИЙ. Я русский бы выучил только за то…
 

Scud

Новичок
First you have to declare right encoding in xml declaration
Код:
 $v= "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
You'll use utf-8 so declare it with utf-8 not iso.

Second you have to covert file names received from readdir() from Cyrillic encoding into utf-8, iconv() will help you.
 
Сверху