<?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/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>MujuuLog &#187; PHP</title>
	<atom:link href="http://mujuu.org/weblog/cat/web_memo/php/feed" rel="self" type="application/rss+xml" />
	<link>http://mujuu.org/weblog</link>
	<description>Web・自転車・写真など適当なメモ書き的なブログサイトです。</description>
	<lastBuildDate>Mon, 05 Dec 2011 14:45:08 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://mujuu.org/weblog/cat/web_memo/php/feed" />
		<item>
		<title>mbstringが使えないサーバーで&#8230;</title>
		<link>http://mujuu.org/weblog/web_memo/225</link>
		<comments>http://mujuu.org/weblog/web_memo/225#comments</comments>
		<pubDate>Sat, 13 Mar 2010 10:32:40 +0000</pubDate>
		<dc:creator>shin2</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webメモ書き]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.mujuu.org/weblog/web_memo/225</guid>
		<description><![CDATA[フォームメールを作ることになった。 一瞬文字コード変換が困ったけど、調べたら jcode.php というライブラリーで解決でたので良かった。 mbstringエミュレータというのもあるみたい。]]></description>
			<content:encoded><![CDATA[<p>フォームメールを作ることになった。<br />
一瞬文字コード変換が困ったけど、調べたら jcode.php というライブラリーで解決でたので良かった。<br />
mbstringエミュレータというのもあるみたい。</p>
]]></content:encoded>
			<wfw:commentRss>http://mujuu.org/weblog/web_memo/225/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://mujuu.org/weblog/web_memo/225" />
	</item>
		<item>
		<title>fgetcsv()で文字化け。</title>
		<link>http://mujuu.org/weblog/web_memo/211</link>
		<comments>http://mujuu.org/weblog/web_memo/211#comments</comments>
		<pubDate>Mon, 18 May 2009 10:36:24 +0000</pubDate>
		<dc:creator>shin2</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webメモ書き]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.mujuu.org/weblog/?p=211</guid>
		<description><![CDATA[PHPでfgetcsv()を使用してCSVファイルを読み、2次元配列に格納したときに日本語の部分が文字化けたのでメモ。（しかも先頭から5文字ぐらいだけ） 調べてみると、よう分からんけどPHP5.0でfgetcsv()の仕 [...]]]></description>
			<content:encoded><![CDATA[<p>PHPでfgetcsv()を使用してCSVファイルを読み、2次元配列に格納したときに日本語の部分が文字化けたのでメモ。（しかも先頭から5文字ぐらいだけ）<br />
調べてみると、よう分からんけどPHP5.0でfgetcsv()の仕様がが変わったとかなんとか&#8230;。<br />
ロケール設定を考慮するようになったとかなんとか&#8230;。</p>
<p><span id="more-211"></span></p>
<p>で、確認してないけど一応対策らしきものがあるみたいだ。<br />
csvファイルのデータの日本語の部分を「&#8221;」で囲うと文字化けしないとか。fgetcsv()の前にsetlocale(LC_ALL, &#8216;ja_JP.eucJP&#8217;);を設定するとか（CSVファイルの文字コードを選ぶらしいからいまいち？）。<br />
その他に、<a href="http://yossy.iimp.jp/wp/?p=56" target="_blank">fgetcsv_reg()</a>という関数をfgetcsv()のかわりに自作して、解決してくれている人がいるみたいです。使い勝手が変わらなくて良いみたい。</p>
<p>結局、2次元配列になればなんだっていいので、file()とexplode()で対応。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">///CSV読み込み</span>
$2d_array <span style="color: #339933;">=</span> LoadCsv<span style="color: #009900;">&#40;</span>CSV_FILE_PATH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> LoadCsv <span style="color: #009900;">&#40;</span><span style="color: #000088;">$filepath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$enc_set</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'EUC-JP'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$enc_base</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'SJIS'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filepath</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: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filepath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filepath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span>count<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ereg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>$&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ereg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>$&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> array_mb_encoding<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$enc_set</span><span style="color: #339933;">,</span> <span style="color: #000088;">$enc_base</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$array</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//配列のデータを出力に合わせてエンコード</span>
<span style="color: #000000; font-weight: bold;">function</span> array_mb_encoding<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #000088;">$enc_set</span><span style="color: #339933;">,</span> <span style="color: #000088;">$enc_base</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span>count<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_convert_encoding</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$enc_set</span><span style="color: #339933;">,</span> <span style="color: #000088;">$enc_base</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$array</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://mujuu.org/weblog/web_memo/211/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://mujuu.org/weblog/web_memo/211" />
	</item>
	</channel>
</rss>

