On 3 June 2010 22:35, Tanel Tammik <keevitaja@xxxxxxxxx> wrote: > Hi, > > does anyone know how to convert all files in a directory and in it's > subdirectories into utf8 encoding? i am using komodo edit as text-editor. > may it has a feature which i cannot find... > > Br > Tanel > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > What encoding are they currently set to? iconv() [1] and mb_convert_encoding() [2] may both be up to the job. <?php // UNTESTED $FilesLocation = 'C:/Work'; $FromEncoding = 'ISO-8859-1'; $ToEncoding = 'UTF-8'; foreach(new DirectoryIterator($FilesLocation) as $File) { file_put_contents($File->getPathname(), iconv($FromEncoding, $ToEncoding, file_get_contents($File->getPathname()))); // file_put_contents($File->getPathname(), mb_convert_encoding(file_get_contents($File->getPathname()), $ToEncoding, $FromEncoding)); } ?> If the files are XML with a xml tag like ... <?xml version="1.0" encoding="iso-8859-1" ?> then you would have to add additional code to edit that line also. Richard. [1] http://docs.php.net/manual/en/function.iconv.php [2]http://docs.php.net/manual/en/function.mb-convert-encoding.php -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php