Re: convert files utf8
| From: | Shreyas | Date: | Fri, 04 Jun 2010 10:46:58 +0000 |
| Subject: | Re: convert files utf8 | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-305798@lists.php.net to get a copy of this message | ||
I bank on Notepad++ (open source editor) to do such a thing. It can convert
an ASCI file to UTF -8.
Give it a shot.
On Fri, Jun 4, 2010 at 2:02 PM, Richard Quadling <rquadling@gmail.com>wrote:
> On 3 June 2010 22:35, Tanel Tammik <keevitaja@gmail.com> 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
>
>
--
Regards,
Shreyas