SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face reading file names in diffrent languages

    Hi,
    im creating a app which will read files/directories and output it in json key/value pair. the folder or the files will named be in english or in any other language , but the problem is i see "?????" for files/dirs named in other languages im also sending utf8 headers:

    here is the code:

    Rpc.php :
    PHP Code:
    <?php
    require('config.php');
    require(
    'dir.php');
    $dir = new dir();
    header('Content-type:text/javascript; charset=utf-8');

    $action clean($_GET['act']);
    if(
    $action == 'speakers'){
        
    $results "[ ";
        
    $data $dir->get_speakers();
        for (
    $i=0;$i<count($data);$i++){
            
    $results .= '["'.$data[$i]['speaker'].'" , "'.$data[$i]['path'].'"],';
        }
        
    $results substr($results , -1);
        
    $results .= ']';
        echo 
    $results;
    }
    elseif(
    $action "categories" && $_GET['speaker'] != ''){
        
    $speaker clean($_GET['speaker']);
        
    $results "[ ";
        
    $data $dir->get_categories($speaker);
        for (
    $i=0;$i<count($data);$i++){
            
    $results .= '["'.$data[$i]['category'].'" , "'.$data[$i]['path'].'"],';
        }
        
    $results substr($results , -1);
        
    $results .= ']';
        echo 
    $results;
    }
    elseif(
    $action "speeches" && $_GET['cat'] != ''){
        
    $cat clean($_GET['cat']);
        
    $results "[ ";
        
    $data $dir->get_files($cat);
        for(
    $i=0;$icount($data);$i++){
            
    $results .= '["'.$data[$i]['title'].'" , "'.$data[$i]['path'].'"],';
        }
        
    $results substr($results , -1);
        
    $results .= ']';
        echo 
    $results;
    }
    ?>

    and dir.php

    PHP Code:
    <?php
    class dir{
        function 
    get_speakers()
        {
            
            
    $dh opendir('./data');
            while (
    false !== ($filename readdir($dh))) {
                if (
    $filename != '..' && $filename != '.' && is_dir('data/'.$filename)) {
                    
    $files[] = array('speaker' => $filename 'path' => $filename);
                }
            }
            return 
    $files;
        }
        function 
    get_categories($speaker)
        {
            
    $dh opendir('./data/'.$speaker);
            while (
    false !== ($filename readdir($dh))) {
                if (
    $filename != '..' && $filename != '.' && is_dir('./data/'.$speaker.'/'.$filename)) {
                    
    $files[] = array('category' => $filename 'path' => $speaker.'/'.$filename);
                }
            }
            return 
    $files;
        }
        function 
    get_files($category){
            
    $dh opendir('./data/'.$category);
            
    $ext = array('rm' 'mp3' 'mp4' 'wma' 'ram' 'wav');
            while (
    false !== ($filename readdir($dh))) {
            
    $extension substr($filename , -3);
                if (
    $filename != '..' && $filename != '.' && is_file('./data/'.$category.'/'.$filename) && in_array($extension $ext)) {
                    
    $files[] = array('title' => substr($filename 0,-4) , 'path' => $category.'/'.$filename);
                }
            }
            return 
    $files;
        }
    }
    ?>

  2. #2
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason you see "????" in your browser is because you don't have the character set for that language installed. There is nothing you can do about it in your PHP code, it's a client issue.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have i can see the folder/file name in windows explorer but not in browser

  4. #4
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mmm i hadn't have to do anything related with character sets, but maybe this article might help you.

    http://www.dangrossman.info/2007/05/...tf8-databases/

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually im not using database im talking about file system


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •