2012-02-24 3 views
0

myFolderi имеет тысячи файлов изображений с текстом ключевого слова для имени. Я пытаюсь читать из списка изображений и загружать текст в поле dB. проблема в том, что в каком-то тексте есть символы utf8, такие как l'Été, которые появляются так: tчтение файлов вставка текста в mysql

Как я могу читать иностранные символы, чтобы акценты вставлялись в поле dB? это, как им обработка сейчас

function ListFiles($dir) { 

if($dh = opendir($dir)) { 

    $files = Array(); 
    $inner_files = Array(); 

    while($file = readdir($dh)) { 
     if($file != "." && $file != ".." && $file[0] != '.') { 
      if(is_dir($dir . "/" . $file)) { 
       $inner_files = ListFiles($dir . "/" . $file); 
       if(is_array($inner_files)) $files = array_merge($files, $inner_files); 
      } else { 
       array_push($files, $dir . "/" . $file);//$dir = directory name 
       //array_push($files, $dir); 
      } 
     }    
    } 
    closedir($dh); 
    return $files; 
} 
} 

    foreach (ListFiles('../../myDirectory') as $key=>$file){ 
//$file = preg_replace('@[^\0-\x80]@u',"", $file); 
    echo $file ."<br />"; 
} 

это производит один и тот же результат

$str = "l’Été"; 
utf8_decode($str); 
echo $str; 
+3

'utf8_decode()' -. http://php.net/manual/en/function.utf8-decode.php –

+0

база данных и/или таблицы должны быть установлены для utf (сопоставление и/или набор символов см.: (http://dev.mysql.com/doc/refman/5.0/en/charset-table.html)) – horatio

+0

см. также: http: //developer.loftdigital. com/blog/php-utf-8-cheatsheet – horatio

ответ

0

Это решение может работать для вас, это будет цикл через все файлы в directoy, а затем recursivly через любые каталоги пока не закончится массивный массив файлов.

Ive добавил некоторые вопросы, которые вы хотите изменить, например, либо Mutli или одиночные массивы измерения (все зависит от того, если вы можете сохранить структуру папок.

, а также если вы хотите, чтобы файл продление будет сохранен при сохранении имя файла БД

код

function recursive_search_dir($dir) { 
    if ($handle = opendir($dir)) { 
    while (false !== ($file = readdir($handle))) { 
    if (in_array($file,array(".",".."))) 
     continue; // We dont want to do anything with parent/current directory. 

    if (is_dir($file)) { 
     $result[] = recursive_search_dir($file); // Multi-dimension 
      # OR 
     array_merge($result,recursive_search_dir($file));// Single-dimension if you dont care about folder structure. 
    } else { 
     $result[] = utf8_decode($file); // full file name (includes extention) 
      # OR 
     $result[] = utf8_decode(filename($file,PATHINFO_FILENAME)); // if you only want to capture the name and not the extention. 
    } 
    } 
    closedir($handle); 
    } 
    return $result; 
} 
$files = recursive_search_dir("."); // recursively searcht the current directory.