html编辑器如何去掉bom字符

html编辑器如何去掉bom字符,第1张

先来看看什么是bom头?

在utf-8编码文件中BOM在文件头部,占用三个字节,用来标示该文件属于utf-8编码,现在已经有很多软件识别bom头,但是还有些不能识别bom头,比如PHP就不能识别bom头,这也是用记事本编辑utf-8编码后执行就会出错的原因了。

去掉bom头的办法,简单的是下面两种:

1、editplus去BOM头的方法

编辑器调整为UTF8编码格式后,保存的文件前面会多出一串隐藏的字符(也即是BOM),用于编辑器识别这个文件是否是以UTF8编码。 运行Editplus,点击工具,选择首选项,选中文件,UTF-8标识选择 总是删除签名,

然后对PHP文件编辑和保存后的PHP文件就是不带BOM的了。

2、ultraedit去除bom头办法

打开文件后,另存为选项的编码格式里选择(utf-8 无bom头),确定就ok了

怎么样,去掉bom头很简单吧

3、专门写的去除文件BOM头的程序,现在公布出来,可以放在项目根目录,然后运行。

Php代码,请使用工具条复制代码

view sourceprintabout

01

<?php

02

if (isset($_GET['dir'])){ //设置文件目录

03

$basedir=$_GET['dir']

04

}else{

05

$basedir = '.'

06

}

07

$auto = 1

08

checkdir($basedir)

09

function checkdir($basedir){

10

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

11

while (($file = readdir($dh)) !== false) {

12

if ($file != '.' &&$file != '..'){

13

if (!is_dir($basedir."/".$file)) {

14

echo "filename: $basedir/$file ".checkBOM("$basedir/$file")." <br>"

15

}else{

16

$dirname = $basedir."/".$file

17

checkdir($dirname)

18

}

19

}

20

}

21

closedir($dh)

22

}

23

}

24

function checkBOM ($filename) {

25

global $auto

26

$contents = file_get_contents($filename)

27

$charset[1] = substr($contents, 0, 1)

28

$charset[2] = substr($contents, 1, 1)

29

$charset[3] = substr($contents, 2, 1)

30

if (ord($charset[1]) == 239 &&ord($charset[2]) == 187 &&ord($charset[3]) == 191) {

31

if ($auto == 1) {

32

$rest = substr($contents, 3)

33

rewrite ($filename, $rest)

34

return ("<font color=red>BOM found, automatically removed._<a href=http://blog.csdn.net/s394032675>csdn.net</a></font>")

35

} else {

36

return ("<font color=red>BOM found.</font>")

37

}

38

}

39

else return ("BOM Not Found.")

40

}

41

function rewrite ($filename, $data) {

42

$filenum = fopen($filename, "w")

43

flock($filenum, LOCK_EX)

44

fwrite($filenum, $data)

45

fclose($filenum)

46

}

47

?>

好了,以上就是去掉bom头的一些方法,其实做php的时候不建议用记事本的,最好是用一些专业的ide,这样能防止以上的一些小错误,来提高我们的编码效率和质量!

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function catch_keydown(sel)

{

switch(event.keyCode)

{

case 13:

//Enter

sel.options[sel.length] = new Option("","",false,true)

event.returnValue = false

break

case 27:

//Esc

alert("text:" + sel.options[sel.selectedIndex].text + ", value:" + sel.options[sel.selectedIndex].value + "")

event.returnValue = false

break

case 46:

//Delete

if(confirm("Delete!?"))

{

sel.options[sel.selectedIndex] = null

if(sel.length>0)

{

sel.options[0].selected = true

}

}

event.returnValue = false

break

case 8:

//Back Space

var s = sel.options[sel.selectedIndex].text

sel.options[sel.selectedIndex].text = s.substr(0,s.length-1)

event.returnValue = false

break

}

}

function catch_press(sel)

{

sel.options[sel.selectedIndex].text = sel.options[sel.selectedIndex].text + String.fromCharCode(event.keyCode)

event.returnValue = false

}

//End -->

</script>

</head>

<select size="1" name="fh_cp" onKeyDown="catch_keydown(this)" onKeyPress="catch_press(this)" style="font-size:12px">

<option></option>

<?if ($FH_CP<>""){

$seek_cp="select gg,cp from bom where lh=\'$FH_CP\' "

$result_cp=@pg_exec($link,$seek_cp)

$GG=trim(pg_result($result_cp,0,"gg"))

$CP=trim(pg_result($result_cp,0,"cp"))

$C_G=$CP.\' \'.$GG

echo "<option selected value=\\"$FH_CP\\">$C_G</option>" }?>

<?for($j=0$j<$row_fh$j++){

$gg_fh=trim(pg_result($result_fh,$j,"gg"))

$cp_fh=trim(pg_result($result_fh,$j,"cp"))

$seek_lh="select * from bom where cp=\'$cp_fh\' and gg=\'$gg_fh\' "

$result_lh=pg_exec($link,$seek_lh)

$lh_fh=trim(pg_result($result_lh,0,"lh"))

$cp_gg=$cp_fh.\' \'.$gg_fh

if($lh_fh==$FH_CP){

echo "<option selected value=\\"$lh_fh\\">$cp_gg</option>"

}

else{

echo "<option value=\\"$lh_fh\\">$cp_gg</option>"

}

}

?>

</select>

2000年__月__日翡翠台:蜡笔小王国

2000年04月17日翡翠台:百变小樱Magic Card

2000年04月26日翡翠台:玻璃面具

2000年__月__日翡翠台:数码暴龙系列

2000年11月11日翡翠台:小魔女Doremi

2003年01月25日翡翠台:音乐小彗星

2003年__月__日翡翠台:棋灵王

2003年07月06日翡翠台:天使·爱·美纱

2003年__月__日翡翠台:重力王

2004年06月06日翡翠台:网络英雄洛克人

2004年06月15日翡翠台:机动战士特种计划

2004年09月25日翡翠台:魔法小神童加旋

2004年08月27日儿童台:火影忍者

2004年11月19日翡翠台:星球流浪记

200_年__月__日翡翠台:哈姆太郎

2005年01月03日翡翠台:驭龙少年

2005年01月05日翡翠台:星梦美少女

2005年01月07日翡翠台:召唤王

2005年04月03日翡翠台:火之鸟

2005年04月09日翡翠台:我要上太空

2005年05月12日翡翠台:银河五虎将

2005年06月02日翡翠台:SD高达

2005年07月02日翡翠台:精乖宝宝Gugo

2005年07月05日翡翠台:唱k小鱼仙

2005年11月05日翡翠台:龙王传说

2005年__月__日翡翠台:滴骰孖妹系列

2006年01月26日翡翠台:翼之奇幻旅程

2006年04月11日翡翠台:日式面包王

2006年04月28日翡翠台:甲虫王者

2006年05月16日翡翠台:BOM BOMd珠人太空战士〔儿童台为BOM BOMd珠人太空保卫篇〕

2006年06月04日翡翠台:阴阳大战记

2006年06月24日翡翠台:机动战士特种命运

2006年07月03日翡翠台:Keroro军曹

2006年07月16日翡翠台:光之美少女

2006年08月12日翡翠台:玻璃面具

2006年10月08日翡翠台:飞艇急转弯

2006年__月__日儿童台:我们这一家

2006年12月31日翡翠台:宠物小精灵超世代

2007年03月30日翡翠台:猫狗宠物街


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7273559.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-03
下一篇 2023-04-03

发表评论

登录后才能评论

评论列表(0条)

保存