Yii Framework Forum: Recursive UTF-8 conversion (BASH) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Recursive UTF-8 conversion (BASH) Rate Topic: -----

#1 User is offline   rhomb 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 28-September 11

Posted 24 August 2012 - 03:19 AM

Good Morning everyone.

Yesterday we had a Problem with non UTF-8 Files in the Project (happened in accident).

So I wrote a small bash script that should do the trick. It recursively converts all .php files to UTF-8 encoding

Requirements:
- Linux system
- iconv

Script:
for i in $(find -name '*.php');do encoding=$(file -bi $i | sed -e 's/.*[ ]charset=//'); iconv -f $encoding -t UTF-8 -o $i $i; done


Greetings
rho
0

#2 User is offline   julianm 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 04-January 12

Posted 13 March 2013 - 07:32 AM

Sorry, but it didn't work for me. All the files ended with 0 byte after running the command. Fortunately I still have the backup.
0

#3 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,648
  • Joined: 17-January 09
  • Location:Russia

Posted 13 March 2013 - 10:30 AM

We have ready to use commands for it in Yii repo:

https://github.com/y...kBomCommand.php
https://github.com/y...Utf8Command.php
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#4 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 13 March 2013 - 10:45 AM

View Postrhomb, on 24 August 2012 - 03:19 AM, said:

for i in $(find -name '*.php');do encoding=$(file -bi $i | sed -e 's/.*[ ]charset=//'); iconv -f $encoding -t UTF-8 -o $i $i; done


Whoa, dude ... find has got this nifty -exec param. At least you could've used xargs :o
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#5 User is offline   rhomb 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 28-September 11

Posted 29 March 2013 - 06:54 AM

@DASourcerer :P was really qnd and late at night..

@Samdark.. wow didn't know that, thanks for the hint
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users