<?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>编码转换 &#8211; LPC影子技术分享</title>
	<atom:link href="https://www.mudbest.com/tag/%E7%BC%96%E7%A0%81%E8%BD%AC%E6%8D%A2/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mudbest.com</link>
	<description>行影不离,忘之却步.</description>
	<lastBuildDate>Mon, 31 Dec 2012 21:47:49 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.1</generator>
	<item>
		<title>PHP处理GBK转换为UTF8字符集编码时报错</title>
		<link>https://www.mudbest.com/php%e5%a4%84%e7%90%86gbk%e8%bd%ac%e6%8d%a2%e4%b8%bautf8%e5%ad%97%e7%ac%a6%e9%9b%86%e7%bc%96%e7%a0%81%e6%97%b6%e6%8a%a5%e9%94%99/</link>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Mon, 31 Dec 2012 21:47:49 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[gbk]]></category>
		<category><![CDATA[iconv]]></category>
		<category><![CDATA[编码转换]]></category>
		<category><![CDATA[错误]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=1743</guid>

					<description><![CDATA[函数介绍： iconv()介绍 iconv函数可以将一种已知的字符集文件转换成另一种已知的字符集文件。例如：从 ... <a title="PHP处理GBK转换为UTF8字符集编码时报错" class="read-more" href="https://www.mudbest.com/php%e5%a4%84%e7%90%86gbk%e8%bd%ac%e6%8d%a2%e4%b8%bautf8%e5%ad%97%e7%ac%a6%e9%9b%86%e7%bc%96%e7%a0%81%e6%97%b6%e6%8a%a5%e9%94%99/" aria-label="阅读 PHP处理GBK转换为UTF8字符集编码时报错">阅读更多</a>]]></description>
										<content:encoded><![CDATA[<p><strong>函数介绍：</strong></p>
<p><strong>iconv()介绍</strong><br />
iconv函数可以将一种已知的字符集文件转换成另一种已知的字符集文件。例如：从GB2312转换为UTF-8。<br />
iconv函数在php5中内置，GB字符集默认打开。</p>
<p><strong>iconv()错误</strong><br />
iconv在转换字符”—”到gb2312时会出错，解决方法是在需要转成的编码后加 “//IGNORE”，也就是iconv函数第二个参数后。如下：<br />
iconv(&#8220;UTF-8&#8221;, &#8220;GB2312//IGNORE&#8221;, $data)<br />
ignore的意思是忽略转换时的错误，如果没有ignore参数，所有该字符后面的字符串都无法被保存。<span id="more-1743"></span></p>
<p>iconv()例子</p>
<p><strong>例1：</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
echo $str= ‘你好,这里是卖咖啡!’;
echo '&lt;br /&gt;';
echo iconv('GB2312', 'UTF-8', $str); //将字符串的编码从GB2312转到UTF-8
echo '&lt;br /&gt;';
echo iconv_substr($str, 1, 1, 'UTF-8'); //按字符个数截取而非字节
print_r(iconv_get_encoding()); //得到当前页面编码信息
echo iconv_strlen($str, 'UTF-8'); //得到设定编码的字符串长度
?&gt;
</pre>
<p><strong>例2：</strong><br />
如果你的PHP文件是UTF-8编码的，那么下面的代码就可以正确输出：</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$str='我爱百度';
$utf='';
for ($i=0;$i&lt;strlen($str);$i++) $utf.=sprintf(&quot;%%%02X&quot;,ord(substr($str,$i,1)));
echo $utf;
?&gt;
</pre>
<p>如果你的PHP文件是GB的，那么下面的代码可以工作：</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$str='我爱百度';
$str=iconv(&quot;GBK&quot;, &quot;UTF-8&quot;, $str);
$utf='';
for ($i=0;$i&lt;strlen($str);$i++) $utf.=sprintf(&quot;%%%02X&quot;,ord(substr($str,$i,1)));
echo $utf;
?&gt;
</pre>
<p>以上情况下，程序输出的内容是：</p>
<pre class="brush: plain; title: ; notranslate">
%E6%88%91%E7%88%B1%E7%99%BE%E5%BA%A6
</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
