<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Movie Castle &#187; UTF</title>
	<atom:link href="http://www.eemir3.com/tag/utf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.eemir3.com</link>
	<description>以对电影的执着,撰写扭曲&#38;颠倒之现世,即使黑暗也会一往无前.</description>
	<lastBuildDate>Sat, 05 Nov 2011 17:27:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>移除PHP中BOM的方法</title>
		<link>http://www.eemir3.com/2008/05/remove-bom-from-php-in-utf8/</link>
		<comments>http://www.eemir3.com/2008/05/remove-bom-from-php-in-utf8/#comments</comments>
		<pubDate>Tue, 06 May 2008 04:29:35 +0000</pubDate>
		<dc:creator>Yacca</dc:creator>
				<category><![CDATA[行业&博客]]></category>
		<category><![CDATA[BOM]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[UTF]]></category>

		<guid isPermaLink="false">http://www.eemir3.com/index.php/2008/05/06/remove-bom-from-php-in-utf8/</guid>
		<description><![CDATA[PHP...还真麻烦,尤其是在Win主机下 　　好兄弟友情支持的虚拟主机最近老出问题,仔细询问了缘由,看来还是技术维护人员不到位造成,且服务器是Win2003+IIS,不稳定之余对PHP的支持也存在些微的问题. 不想去埋怨什么,期待早点完成维护即可. 　　今天上午挺意外的发现服务器恢复,但我的Movie Castle页面显示却很奇怪...全屏,且上方多了一行小空行,测试浏览器为IE7.然后去Firefox下查看,发现页面的Width正常,但上方的小空行依然存在-.- 　　我是善于Google的人,于是遇到不明白的先询问这本百科全书. 得到的答案是主题PHP文件编码是UTF-8 with bom造成的,至于这个bom是什么,看下这个中文解释吧. 　　在UCS 编码中有一个叫做"ZERO WIDTH NO-BREAK SPACE"的字符，它的编码是FEFF。而FFFE在UCS中是不存在的字符，所以不应该出现在实际传输中。UCS规范建议我们在传输字节流前，先传输 字符"ZERO WIDTH NO-BREAK SPACE"。这样如果接收者收到FEFF，就表明这个字节流是Big-Endian的；如果收到FFFE，就表明这个字节流是Little- Endian的。因此字符"ZERO WIDTH NO-BREAK SPACE"又被称作BOM。 　　UTF-8不需要BOM来表明字节顺序，但可以用BOM来表明编码方式。字符"ZERO WIDTH NO-BREAK SPACE"的UTF-8编码是EF BB BF。所以如果接收者收到以EF BB BF开头的字节流，就知道这是UTF-8编码了。 　　Windows就是使用BOM来标记文本文件的编码方式的。 　 　　很显然...我的小空行是因为这个bom而产生的. 　　找到问题后的就是解决问题.去WP群里问了声,得到了一些建议,但个人觉得CSS样式之前在相同的环境下没有一点问题,没理由现在突然显示不了! 还是先解决已知问题吧...Google告诉我了很多去除bom的方法,但操作上来讲都有点烦,最后终于找到了个称心如意滴~muhahaha 一个自动移除bom的小程序...备份后大胆的试用,果然问题立刻解决. 　    &#60;?php //remove the utf-8 boms //by magicbug at gmail dot com if (isset($_GET['dir'])){ //config the basedir $basedir=$_GET['dir']; [...]]]></description>
			<content:encoded><![CDATA[<p align="center"><a href="http://www.eemir3.com/wp-content/uploads/2008/05/php.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" src="http://www.eemir3.com/wp-content/uploads/2008/05/php-thumb.png" border="0" alt="php" width="244" height="158" /></a></p>
<p align="center">PHP...还真麻烦,尤其是在Win主机下</p>
<p><span id="more-1352"></span></p>
<p>　　好兄弟友情支持的虚拟主机最近老出问题,仔细询问了缘由,看来还是技术维护人员不到位造成,且服务器是Win2003+IIS,不稳定之余对PHP的支持也存在些微的问题. 不想去埋怨什么,期待早点完成维护即可.</p>
<p>　　今天上午挺意外的发现服务器恢复,但我的<a title="Movie Castle" href="http://www.eemir3.com/" target="_blank">Movie Castle</a>页面显示却很奇怪...全屏,且上方多了一行小空行,测试浏览器为IE7.然后去Firefox下查看,发现页面的Width正常,但上方的小空行依然存在-.-</p>
<p>　　我是善于Google的人,于是遇到不明白的先询问这本百科全书. 得到的答案是主题PHP文件编码是UTF-8 with bom造成的,至于这个bom是什么,看下这个中文解释吧.</p>
<blockquote><p>　　在UCS 编码中有一个叫做"ZERO WIDTH NO-BREAK SPACE"的字符，它的编码是FEFF。而FFFE在UCS中是不存在的字符，所以不应该出现在实际传输中。UCS规范建议我们在传输字节流前，先传输 字符"ZERO WIDTH NO-BREAK SPACE"。这样如果接收者收到FEFF，就表明这个字节流是Big-Endian的；如果收到FFFE，就表明这个字节流是Little- Endian的。因此字符"ZERO WIDTH NO-BREAK SPACE"又被称作BOM。</p>
<p>　　UTF-8不需要BOM来表明字节顺序，但可以用BOM来表明编码方式。字符"ZERO WIDTH NO-BREAK SPACE"的UTF-8编码是EF BB BF。所以如果接收者收到以EF BB BF开头的字节流，就知道这是UTF-8编码了。</p>
<p>　　Windows就是使用BOM来标记文本文件的编码方式的。</p></blockquote>
<p>　</p>
<p>　　很显然...我的小空行是因为这个bom而产生的.</p>
<p>　　找到问题后的就是解决问题.去WP群里问了声,得到了一些建议,但个人觉得CSS样式之前在相同的环境下没有一点问题,没理由现在突然显示不了! 还是先解决已知问题吧...Google告诉我了很多去除bom的方法,但操作上来讲都有点烦,最后终于找到了个称心如意滴~muhahaha 一个自动移除bom的小程序...备份后大胆的试用,果然问题立刻解决.</p>
<p>　<br />
  </p>
<blockquote><p><!--p<br--></p>
<pre><span style="color: #0000ff;">&lt;?</span>php
<span style="color: #008000;">//remove the utf-8 boms</span>
<span style="color: #008000;">//by magicbug at gmail dot com</span>

<a style="color: #0000ff" href="http://www.php.net/if">if</a> (isset($_GET['<span style="color: #8b0000;">dir</span>'])){ <span style="color: #008000;">//config the basedir</span>
	$basedir=$_GET['<span style="color: #8b0000;">dir</span>'];
}<a style="color: #0000ff" href="http://www.php.net/else">else</a>{
	$basedir = '<span style="color: #8b0000;">.</span>';
} 

$auto = 1; 

checkdir($basedir);

<a style="color: #0000ff" href="http://www.php.net/function">function</a> checkdir($basedir){
	<a style="color: #0000ff" href="http://www.php.net/if">if</a> ($dh = <a style="color: #ffa500" href="http://www.php.net/opendir">opendir</a>($basedir)) {
		<a style="color: #0000ff" href="http://www.php.net/while">while</a> (($<a style="color: #ffa500" href="http://www.php.net/file">file</a> = <a style="color: #ffa500" href="http://www.php.net/readdir">readdir</a>($dh)) !== <a style="color: #0000ff" href="http://www.php.net/false">false</a>) {
			<a style="color: #0000ff" href="http://www.php.net/if">if</a> ($<a style="color: #ffa500" href="http://www.php.net/file">file</a> != '<span style="color: #8b0000;">.</span>' &amp;&amp; $<a style="color: #ffa500" href="http://www.php.net/file">file</a> != '<span style="color: #8b0000;">..</span>'){
				<a style="color: #0000ff" href="http://www.php.net/if">if</a> (!<a style="color: #ffa500" href="http://www.php.net/is_dir">is_dir</a>($basedir."<span style="color: #8b0000;">/</span>".$<a style="color: #ffa500" href="http://www.php.net/file">file</a>)) {
					<a style="color: #0000ff" href="http://www.php.net/echo">echo</a> "<span style="color: #8b0000;">filename: $basedir/</span></pre>
<pre><span style="color: #8b0000;">$file </span>".checkBOM("<span style="color: #8b0000;">$basedir/$file</span>")."<span style="color: #8b0000;"> &lt;br&gt;</span>";
				}<a style="color: #0000ff" href="http://www.php.net/else">else</a>{
					$<a style="color: #ffa500" href="http://www.php.net/dirname">dirname</a> = $basedir."<span style="color: #8b0000;">/</span>".</pre>
<pre>$<a style="color: #ffa500" href="http://www.php.net/file">file</a>;
					checkdir($<a style="color: #ffa500" href="http://www.php.net/dirname">dirname</a>);
				}
			}
		}
	<a style="color: #ffa500" href="http://www.php.net/closedir">closedir</a>($dh);
	}
}

<a style="color: #0000ff" href="http://www.php.net/function">function</a> checkBOM ($filename) {
	<a style="color: #0000ff" href="http://www.php.net/global">global</a> $auto;
	$contents = file_get_contents($filename);
	$charset[1] = <a style="color: #ffa500" href="http://www.php.net/substr">substr</a>($contents, 0, 1);
	$charset[2] = <a style="color: #ffa500" href="http://www.php.net/substr">substr</a>($contents, 1, 1);
	$charset[3] = <a style="color: #ffa500" href="http://www.php.net/substr">substr</a>($contents, 2, 1);
	<a style="color: #0000ff" href="http://www.php.net/if">if</a> (<a style="color: #ffa500" href="http://www.php.net/ord">ord</a>($charset[1]) == 239 &amp;&amp; <a style="color: #ffa500" href="http://www.php.net/ord">ord</a>($charset[2]) == 187 &amp;&amp;</pre>
<pre> <a style="color: #ffa500" href="http://www.php.net/ord">ord</a>($charset[3]) == 191) {
		<a style="color: #0000ff" href="http://www.php.net/if">if</a> ($auto == 1) {
			$rest = <a style="color: #ffa500" href="http://www.php.net/substr">substr</a>($contents, 3);
			rewrite ($filename, $rest);
			<a style="color: #0000ff" href="http://www.php.net/return">return</a> ("<span style="color: #8b0000;">&lt;font color=red&gt;BOM found, </span></pre>
<pre><span style="color: #8b0000;">automatically</span><span style="color: #8b0000;"> removed.&lt;/font&gt;</span>");
		} <a style="color: #0000ff" href="http://www.php.net/else">else</a> {
			<a style="color: #0000ff" href="http://www.php.net/return">return</a> ("<span style="color: #8b0000;">&lt;font color=red&gt;BOM found.</span></pre>
<pre><span style="color: #8b0000;">&lt;/font&gt;</span>");
		}
	}
	<a style="color: #0000ff" href="http://www.php.net/else">else</a> <a style="color: #0000ff" href="http://www.php.net/return">return</a> ("<span style="color: #8b0000;">BOM Not Found.</span>");
}

<a style="color: #0000ff" href="http://www.php.net/function">function</a> rewrite ($filename, $data) {
	$filenum = <a style="color: #ffa500" href="http://www.php.net/fopen">fopen</a>($filename, "<span style="color: #8b0000;">w</span>");
	<a style="color: #ffa500" href="http://www.php.net/flock">flock</a>($filenum, LOCK_EX);
	<a style="color: #ffa500" href="http://www.php.net/fwrite">fwrite</a>($filenum, $data);
	<a style="color: #ffa500" href="http://www.php.net/fclose">fclose</a>($filenum);
}
<span style="color: #0000ff;">?&gt;</span></pre>
</blockquote>
<p>　</p>
<p>步骤:</p>
<blockquote><p>1.Copy代码到txt文档中,保存成php后缀的文件,命名为111.php</p>
<p>2.将111.php放在网站根目录下</p>
<p>3.打开浏览器,执行<a href="http://root/111.php">http://root/111.php</a></p>
<p>4.一切困扰都解决鸟...空行没了,CSS样式也显示正常了.</p></blockquote>
<p>　</p>
<p>　　撰文留念之...用这个方法可远比将php文件一个个另存为utf-8 without bom方便呢!!!</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.eemir3.com/2008/01/gossip-girl-season01/" title="《绯闻女孩》第一季">《绯闻女孩》第一季</a> (1)</li><li><a href="http://www.eemir3.com/2008/11/feed-eemir3-com/" title="将本站RSS Feed输出到二级域名">将本站RSS Feed输出到二级域名</a> (57)</li><li><a href="http://www.eemir3.com/2007/12/redcrossdm/" title="红十字会DM">红十字会DM</a> (0)</li><li><a href="http://www.eemir3.com/2008/01/sennheiser-mx-w1/" title="Sennheiser: MX W1">Sennheiser: MX W1</a> (0)</li><li><a href="http://www.eemir3.com/2007/04/ken-park-comment/" title="青少年伦理片 《天地无伦》">青少年伦理片 《天地无伦》</a> (2)</li><li><a href="http://www.eemir3.com/2009/10/lie-to-me-season2-ep1/" title="《Lie to me》第二季EP1">《Lie to me》第二季EP1</a> (9)</li><li><a href="http://www.eemir3.com/2006/09/taking-medication-cant-sleep/" title="吃了药,睡不着&#8230;">吃了药,睡不着&#8230;</a> (0)</li><li><a href="http://www.eemir3.com/2008/01/mercury-rising/" title="越来越厌倦动作片了">越来越厌倦动作片了</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.eemir3.com/2008/05/remove-bom-from-php-in-utf8/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
	</channel>
</rss>

