<?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>勿慢牛 &#187; 乱码</title>
	<atom:link href="http://klniu.com/post/tag/messy-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://klniu.com</link>
	<description>『勿慢牛个人博客』</description>
	<lastBuildDate>Fri, 06 Jan 2012 06:42:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>dokuwiki中文文件名编码转换</title>
		<link>http://klniu.com/post/dokuwiki-chinese-filename-encoding-conversion/</link>
		<comments>http://klniu.com/post/dokuwiki-chinese-filename-encoding-conversion/#comments</comments>
		<pubDate>Sun, 30 May 2010 10:36:43 +0000</pubDate>
		<dc:creator>勿慢牛</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[ascii2uni]]></category>
		<category><![CDATA[dokuwiki]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[乱码]]></category>

		<guid isPermaLink="false">http://klniu.com/?p=541</guid>
		<description><![CDATA[默认情况下，dokuwiki需要把中文文件进行编码后存储，便会在data文件夹下存在好多形如%ED%类的文件名，不利用管理和SEO，如果你想改变这些，首先要更改dokuwiki对中文文件的存储方式，然后将以前的文件编码重新转换为正常的中文文件名。 第一步可参考上一篇文章http://klniu.com/post/dokuwiki-chinese-file-name-and-address-sitemap-garbled/更改。 而第二步就需要批量处理了，此方法适用于linux系统。我使用的是ubuntu，请大家参考执行： 安装uni2ascii工具： sudo apt-get install uni2ascii 编写脚本： #!/bin/sh times=5 itimes=0 while [ "$itimes" -lt "$times" ] do for oldfile in `find $1 -name "*"` do newfile=`echo $oldfile&#124;ascii2uni -aJ -q` mv -n -v "$oldfile" "$newfile" done itimes=$(($itimes+1)) done 脚本的原理是，遍历目录并转换文件名，然后再将乱码的文件重命名为转换后的文件名。 &#8230; <a href="http://klniu.com/post/dokuwiki-chinese-filename-encoding-conversion/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>默认情况下，dokuwiki需要把中文文件进行编码后存储，便会在data文件夹下存在好多形如%ED%类的文件名，不利用管理和SEO，如果你想改变这些，首先要更改dokuwiki对中文文件的存储方式，然后将以前的文件编码重新转换为正常的中文文件名。</p>
<p>第一步可参考上一篇文章<a href="http://klniu.com/post/dokuwiki-chinese-file-name-and-address-sitemap-garbled/">http://klniu.com/post/dokuwiki-chinese-file-name-and-address-sitemap-garbled/</a>更改。</p>
<p>而第二步就需要批量处理了，此方法适用于linux系统。我使用的是ubuntu，请大家参考执行：</p>
<p>安装uni2ascii工具：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> uni2ascii</pre></div></div>

<p>编写脚本：</p>
<pre class="brush: bash">#!/bin/sh
 times=5
 itimes=0
 while [ "$itimes" -lt "$times" ]
 do
 for oldfile in `find $1 -name "*"`
 do
 newfile=`echo $oldfile|ascii2uni -aJ -q`
 mv -n -v "$oldfile" "$newfile"
 done
 itimes=$(($itimes+1))
 done</pre>
<p>脚本的原理是，遍历目录并转换文件名，然后再将乱码的文件重命名为转换后的文件名。</p>
<p>因为我shell学得不好，所以有一个问题没有解决&#8211;在脚本执行过程中，如果目录已经被更改，脚本继续执行的时候被更改过名字的目录下的文件会无法定位，所以此脚本需要多执行几次，具体次数要视最大目录层数决定，脚本默认5次，如果你目录较多，可以更改times=数字，来决定脚本执行次数。这是一个小问题，脚本并不会损坏文件，只是多执行几次，请放心使用。</p>
<p>脚本编写完成后，执行:</p>
<pre class="brush: bash">sh 脚本名字 被执行的目录   #例如 sh asciiconv.sh /home/username/dokuwiki/data</pre>
]]></content:encoded>
			<wfw:commentRss>http://klniu.com/post/dokuwiki-chinese-filename-encoding-conversion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>dokuwiki中文文件名及sitemap乱码的解决</title>
		<link>http://klniu.com/post/dokuwiki-chinese-file-name-and-address-sitemap-garbled/</link>
		<comments>http://klniu.com/post/dokuwiki-chinese-file-name-and-address-sitemap-garbled/#comments</comments>
		<pubDate>Sun, 30 May 2010 07:52:06 +0000</pubDate>
		<dc:creator>勿慢牛</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[dokuwiki]]></category>
		<category><![CDATA[sitemap]]></category>
		<category><![CDATA[中文]]></category>
		<category><![CDATA[乱码]]></category>

		<guid isPermaLink="false">http://klniu.com/?p=539</guid>
		<description><![CDATA[dokuwiki默认是使用urlencode函数对文件名进行编码后存储的，而索引文章的indexer.php文件在生成sitemap.xml时也会对文件名编码，这样对搜索引擎是不友好的，实际上将这两个编码的功能去掉就可以了。 中文文件名的乱码可以参考http://www.dokuwiki.org/zh:pagename进行更改，即: function utf8_encodeFN&#40;$file, $safe = true&#41; &#123; if &#40;$safe &#38;&#38; preg_match&#40;'#^[a-zA-Z0-9/_\-.%]+$#', $file&#41;&#41; &#123; return $file; &#125; /* 把这个部分注释掉 $file = urlencode($file); $file = str_replace('%2F','/',$file); */ return $file; &#125; &#125; if &#40;!function_exists&#40;'utf8_decodeFN'&#41;&#41; &#123; /** * URL-Decode a filename * * &#8230; <a href="http://klniu.com/post/dokuwiki-chinese-file-name-and-address-sitemap-garbled/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>dokuwiki默认是使用urlencode函数对文件名进行编码后存储的，而索引文章的indexer.php文件在生成sitemap.xml时也会对文件名编码，这样对搜索引擎是不友好的，实际上将这两个编码的功能去掉就可以了。</p>
<p>中文文件名的乱码可以参考<a href="http://www.dokuwiki.org/zh:pagename">http://www.dokuwiki.org/zh:pagename</a>进行更改，即:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> utf8_encodeFN<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$safe</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$safe</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#^[a-zA-Z0-9/_\-.%]+$#'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #666666; font-style: italic;">/* 把这个部分注释掉
     $file = urlencode($file);
     $file = str_replace('%2F','/',$file);
   */</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'utf8_decodeFN'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009933; font-style: italic;">/**
   * URL-Decode a filename
   *
   * This is just a wrapper around urldecode
   *
   * @author Andreas Gohr &lt;andi@splitbrain.org&gt;
   * @see urldecode
   */</span>
  <span style="color: #000000; font-weight: bold;">function</span> utf8_decodeFN<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//$file = urldecode($file); //再注释掉这个语句...</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>而生成sitemap.xml文件的是&quot;/lib/exe/indexer.php&quot;文件，打开这个文件，搜索runSitemapper()函数，在函数下有此语句：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">print</span> <span style="color: #0000ff;">'    &lt;loc&gt;'</span><span style="color: #339933;">.</span>wl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/loc&gt;'</span><span style="color: #339933;">.</span>NL<span style="color: #339933;">;</span></pre></div></div>

<p>其中wl函数为重写url的，在wl函数的定义在&quot;/inc/common.php&quot;文件内，其中有一语句：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$id</span>    <span style="color: #339933;">=</span> idfilter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>idfilter即是进行编码转换的，只需要在common.php中去掉那一行即可。</p>
]]></content:encoded>
			<wfw:commentRss>http://klniu.com/post/dokuwiki-chinese-file-name-and-address-sitemap-garbled/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpexcel导出文件乱码问题</title>
		<link>http://klniu.com/post/phpexcel-char/</link>
		<comments>http://klniu.com/post/phpexcel-char/#comments</comments>
		<pubDate>Sat, 16 May 2009 14:06:17 +0000</pubDate>
		<dc:creator>勿慢牛</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[phpexcel]]></category>
		<category><![CDATA[乱码]]></category>

		<guid isPermaLink="false">http://livesdrop.com/post/phpexcel-char/</guid>
		<description><![CDATA[以前使用phpexcel类导出xls文件时，没有发现有乱码的问题，可是今天再使用的时候就发现文件下载完成后打开时，excel提示文件的格式与文件指定的格式不一致，打开时就乱码，用记事本打开时是空的，挺无奈，于是google了一下，试了好多都不知道是什么原因，后来在不加参数在浏览器打开之后发现左上角有一个锘字，于是恍然大悟，肯定是文件或者包含的文件前面有空格，于是找了找，终于在自己的类文件里发现&#60;?php前面有一个空格,哎！寻找的方法是以前在网上发现的，现在也忘记出处了，就是用UE，在UE的配置里，文件处理-&#62;UTF-8检测，去掉“自动检测UTF-8文件”和“检测UNICODE(UTF-16文件无BOM)”前面的勾，然后重启UE，再打开要查看的文件，就能在文件前面查看有没有类似空格的乱码。]]></description>
			<content:encoded><![CDATA[<p>以前使用phpexcel类导出xls文件时，没有发现有乱码的问题，可是今天再使用的时候就发现文件下载完成后打开时，excel提示文件的格式与文件指定的格式不一致，打开时就乱码，用记事本打开时是空的，挺无奈，于是google了一下，试了好多都不知道是什么原因，后来在不加参数在浏览器打开之后发现左上角有一个锘字，于是恍然大悟，肯定是文件或者包含的文件前面有空格，于是找了找，终于在自己的类文件里发现&lt;?php前面有一个空格,哎！寻找的方法是以前在网上发现的，现在也忘记出处了，就是用UE，在UE的配置里，文件处理-&gt;UTF-8检测，去掉“自动检测UTF-8文件”和“检测UNICODE(UTF-16文件无BOM)”前面的勾，然后重启UE，再打开要查看的文件，就能在文件前面查看有没有类似空格的乱码。</p>
]]></content:encoded>
			<wfw:commentRss>http://klniu.com/post/phpexcel-char/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

