Original article: http://www.yiiframework.com/wiki/570/remove-byte-order-mark-bom-from-files-recursively/

The problem was that all my web applications ran normally on localhost, but on server the Greek characters (or any other no-english characters) displayed with problems.

So, I needed to remove BOM from hundreds view files of Yii from a lot of Yii projects manually. Netbeans has an option to keep files Encoding in utf-8 but not utf-8 without BOM.

My previous solution was the converting in utf-8 without BOM encoding one by one file on notepad++ consuming a lot of my time!

Many servers has not this issue but for other servers this is important. So, after of two hours searching I found a fast way to do that by commands.

(If you have windows, install cygwin first)

1) Open a shell command, go into your root folder that contains the project

2) Run this command

grep -rl $'\xEF\xBB\xBF'  /home/rootfolder/Yii_project  > file_with_boms.txt

3) Now, Run this one

while read l; do sed -i '1 s/^\xef\xbb\xbf//'  $l; done < file_with_boms.txt

Thats it! The BOM will be removed from all files that contained it. Now you can upload your project on your server.

Note: Because I didn't use this way many times and I don't know if it works properly for all cases and files, make first a backup of your project! :)

shell script for replacing tab with spaces and remove bom head from file.

find /path/to/your/folder -type f -exec sed -i 's/\t/    /g' {} \; && grep -rl $'\xEF\xBB\xBF'  /path/to/your/folder  > file_with_boms.txt && while read l; do sed -i '1 s/^\xef\xbb\xbf//'  $l; done < file_with_boms.txt && rm file_with_boms.txt

[Ubuntu] Remove Byte Order Mark (BOM) from files recursively [Forward article]的更多相关文章

  1. 字节顺序标记——BOM,Byte Order Mark

    定义 BOM(Byte Order Mark),字节顺序标记,出现在文本文件头部,Unicode编码标准中用于标识文件是采用哪种格式的编码.     介绍 UTF-8 不需要 BOM,尽管 Unico ...

  2. LITTLE-ENDIAN(小字节序、低字节序) BOM——Byte Order Mark 字节序标记 数据在内存中的存放顺序

    总结: 1. endian 字节存放次序 字节序,顾名思义字节的顺序,再多说两句就是大于一个字节类型的数据在内存中的存放顺序(一个字节的数据当然就无需谈顺序的问题了). 2. LITTLE-ENDIA ...

  3. UTF-8文件的Unicode签名BOM(Byte Order Mark)问题记录(EF BB BF)

    背景 楼主测试的批量发送信息功能上线之后,后台发现存在少量的ERROR日志,日志内容为手机号码格式不正确. 此前测试过程中没有出现过此类问题,从运营人员拿到的发送列表的TXT,号码是符合规则的,且格式 ...

  4. StreamWriter结合UTF-8编码使用不当,会造成BOM(Byte Order Mark )问题生成乱码(转载)

    问: I was using HttpWebRequest to try a rest api in ASP.NET Core MVC.Here is my HttpWebRequest client ...

  5. 文本编辑BOM标记(Byte Order Mark)

    微软的自带记事本程序notepad.exe会给UTF-8编码的文件头加入三个隐藏的字节(即BOM).这是一种很愚蠢的做法.就是为了让编辑器不去猜测文件本身是ASCII码还是UTF-8. 什么是BOM ...

  6. 字节序(byte order)和位序(bit order)

    字节序(byte order)和位序(bit order)  在网络编程中经常会提到网络字节序和主机序,也就是说当一个对象由多个字节组成的时候需要注意对象的多个字节在内存中的顺序.  以前我也基本只了 ...

  7. 编程-Byte order & Bit order

    https://mp.weixin.qq.com/s/B9rKps4YsLiDTBkRks8rmQ 看到比特序和字节序放在一起被提及,想必就已经填补了概念拼图里面缺失的那一块了,这一块正是比特序. 一 ...

  8. ubuntu remove mysql

    ubuntu 彻底删除 mysql 然后重装 mysql 删除 mysql sudo apt-get autoremove --purge mysql-server-5.0sudo apt-get r ...

  9. linux shell 命令学习(4) cut - remove sections from each line of files

    之前写了split命令,split主要是按照行来进行文件的分割,而cut 是按照列来进行文件内容的选取 cut OPTION... [FILE]... 描述: 按列选取FILE的内容进行输出 -d : ...

随机推荐

  1. Javascript正则表达式验证邮箱地址

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> < ...

  2. Arbitrage---poj2240(floyd)

    题目链接:http://poj.org/problem?id=2240 题意:有n个国家的,有m个关系,每个关系的格式是:A B C表示1单位的A国货币可以换B单位C国货币:求是否存在一种方法使得货币 ...

  3. 如何将XML文件写入数据库

    将xml文件转成string public string XMLDocumentToString(XmlDocument doc) { MemoryStream stream = new Memory ...

  4. background-image中url找不到路径,背景图像无法显示

    <div id="body_left_secend_1">                        <img src="~/Images/imag ...

  5. APICloud上有关iOS证书的一些问题

    1. 苹果开发者账号及其区别: 苹果的开发者账号分为个人.公司和企业三类. 个人是99$一年,只能个人使用,可以提交应用到AppStore: 公司的也是99$,但是可以邀请其它成员一起使用,可以提交应 ...

  6. MOGRE学习笔记(1) - OGRE简介及在vs2010下配置

    由于工作需要,花费了一段时间研究OGRE,但是研究的目的是要在vs2010平台下用c#进行MOGRE的开发,不得已才转到MGRE,步骤是首选熟悉MOGRE的一些基础知识,做到在winform下能用MO ...

  7. SQL Server Transaction Log Truncate && Shrink

    目录 什么是事务日志 事务日志的组成 事务日志大小维护方法 Truncate Shrink 索引碎片 总结 什么是事务日志 Transaction log   是对数据库管理系统执行的一系列动作的记录 ...

  8. 压测 502 日志报错 upstream timed out (110: Connection timed out)

    环境介绍 服务器:centos6.5服务:nginx proxy 问题描述: 压测 开发同事 的开发环境项目没事,但是 线上机器 命中%50 ,大量502 php的某些页面打不开,页面提示gatewa ...

  9. 面向对象编程(八)——this关键字

    很多人一提起它,就说“当前对象”,可到底什么是当前对象,是什么当前对象,他自己也不清楚. this(隐式参数) 普通方法中,this总是指向当前调用该方法的对象. 构造方法中,this总是指向正要初始 ...

  10. 前端实战——照片墙gallery的实现

    对应的html代码 <!doctype html> <html lang="zh-hans"> <head> <meta charset= ...