質問編集履歴
3
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -52,7 +52,7 @@
|
|
52
52
|
「テキストエディタで開くとどうなってますか?もしかしたらバイナリエディタのほうがいいかもしれません?」
|
53
53
|
|
54
54
|
⇒以下の画像の通り、テキストエディタで開いても半角スペースが二つ入ってしまっています。また、バイナリエディタで見たところやはり20(半角スペース)が入っておりました。
|
55
|
-

|
56
56
|
|
57
57
|
|
58
58
|
|
2
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -90,5 +90,89 @@
|
|
90
90
|
|
91
91
|
⇒本当ですね...逆でした。しかしながら、これを逆にして試しましたが結果は変わらずでした...
|
92
92
|
|
93
|
+
他に何か解決方法は考えられますでしょうか。
|
93
94
|
|
95
|
+
|
96
|
+
【追記②】
|
97
|
+
|
94
|
-
|
98
|
+
php.iniを調べてみました。
|
99
|
+
|
100
|
+
```
|
101
|
+
; PHP's default character set is set to UTF-8.
|
102
|
+
; http://php.net/default-charset
|
103
|
+
default_charset = "UTF-8"
|
104
|
+
```
|
105
|
+
|
106
|
+
```
|
107
|
+
[mbstring]
|
108
|
+
; language for internal character representation.
|
109
|
+
; This affects mb_send_mail() and mbstrig.detect_order.
|
110
|
+
; http://php.net/mbstring.language
|
111
|
+
;mbstring.language = Japanese
|
112
|
+
|
113
|
+
; Use of this INI entry is deprecated, use global internal_encoding instead.
|
114
|
+
; internal/script encoding.
|
115
|
+
; Some encoding cannot work as internal encoding. (e.g. SJIS, BIG5, ISO-2022-*)
|
116
|
+
; If empty, default_charset or internal_encoding or iconv.internal_encoding is used.
|
117
|
+
; The precedence is: default_charset < internal_encoding < iconv.internal_encoding
|
118
|
+
;mbstring.internal_encoding =
|
119
|
+
|
120
|
+
; Use of this INI entry is deprecated, use global input_encoding instead.
|
121
|
+
; http input encoding.
|
122
|
+
; mbstring.encoding_traslation = On is needed to use this setting.
|
123
|
+
; If empty, default_charset or input_encoding or mbstring.input is used.
|
124
|
+
; The precedence is: default_charset < intput_encoding < mbsting.http_input
|
125
|
+
; http://php.net/mbstring.http-input
|
126
|
+
;mbstring.http_input =
|
127
|
+
|
128
|
+
; Use of this INI entry is deprecated, use global output_encoding instead.
|
129
|
+
; http output encoding.
|
130
|
+
; mb_output_handler must be registered as output buffer to function.
|
131
|
+
; If empty, default_charset or output_encoding or mbstring.http_output is used.
|
132
|
+
; The precedence is: default_charset < output_encoding < mbstring.http_output
|
133
|
+
; To use an output encoding conversion, mbstring's output handler must be set
|
134
|
+
; otherwise output encoding conversion cannot be performed.
|
135
|
+
; http://php.net/mbstring.http-output
|
136
|
+
;mbstring.http_output =
|
137
|
+
|
138
|
+
; enable automatic encoding translation according to
|
139
|
+
; mbstring.internal_encoding setting. Input chars are
|
140
|
+
; converted to internal encoding by setting this to On.
|
141
|
+
; Note: Do _not_ use automatic encoding translation for
|
142
|
+
; portable libs/applications.
|
143
|
+
; http://php.net/mbstring.encoding-translation
|
144
|
+
;mbstring.encoding_translation = Off
|
145
|
+
|
146
|
+
; automatic encoding detection order.
|
147
|
+
; "auto" detect order is changed according to mbstring.language
|
148
|
+
; http://php.net/mbstring.detect-order
|
149
|
+
;mbstring.detect_order = auto
|
150
|
+
|
151
|
+
; substitute_character used when character cannot be converted
|
152
|
+
; one from another
|
153
|
+
; http://php.net/mbstring.substitute-character
|
154
|
+
;mbstring.substitute_character = none
|
155
|
+
|
156
|
+
; overload(replace) single byte functions by mbstring functions.
|
157
|
+
; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),
|
158
|
+
; etc. Possible values are 0,1,2,4 or combination of them.
|
159
|
+
; For example, 7 for overload everything.
|
160
|
+
; 0: No overload
|
161
|
+
; 1: Overload mail() function
|
162
|
+
; 2: Overload str*() functions
|
163
|
+
; 4: Overload ereg*() functions
|
164
|
+
; http://php.net/mbstring.func-overload
|
165
|
+
;mbstring.func_overload = 0
|
166
|
+
|
167
|
+
; enable strict encoding detection.
|
168
|
+
; Default: Off
|
169
|
+
;mbstring.strict_detection = On
|
170
|
+
|
171
|
+
; This directive specifies the regex pattern of content types for which mb_output_handler()
|
172
|
+
; is activated.
|
173
|
+
; Default: mbstring.http_output_conv_mimetype=^(text/|application/xhtml+xml)
|
174
|
+
;mbstring.http_output_conv_mimetype=
|
175
|
+
```
|
176
|
+
mbstring関係は全てコメントアウトされていました。また、
|
177
|
+
;extension=php_mbstring.dll
|
178
|
+
ともなっておりました。
|
1
ご質問の回答追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
(追記いたしました、よろしくお願いいたします。)
|
2
|
+
|
1
3
|
PHPでファイル書き込み(csv出力)の実装をしています。
|
2
4
|
そこで、なぜかタイトルの通り、出力をされたファイルをテキスト形式(.txt)でみると最初の行の最初に半角スペースが入ってしまっています。
|
3
5
|
そのため、CSVでも、一行目一列目のみ半角スペースが2つ入ってしまっています。(画像参照)
|
@@ -34,4 +36,59 @@
|
|
34
36
|
readfile($csvFileName);
|
35
37
|
```
|
36
38
|
|
37
|
-

|
39
|
+

|
40
|
+
|
41
|
+
|
42
|
+
【追記】
|
43
|
+
|
44
|
+
皆さまご回答ありがとうございます。
|
45
|
+
|
46
|
+
出力する内容を隠すためにサンプルの内容を入れたり多少変数名を変えたりしておりまして、
|
47
|
+
その際コード全体として不自然になってしまいました。そのまま投稿したこと申し訳ありません。
|
48
|
+
以下、その部分も補足しつつご質問の回答と、状態を書きたいと思います。
|
49
|
+
|
50
|
+
|
51
|
+
**ご質問内容⓵**
|
52
|
+
「テキストエディタで開くとどうなってますか?もしかしたらバイナリエディタのほうがいいかもしれません?」
|
53
|
+
|
54
|
+
⇒以下の画像の通り、テキストエディタで開いても半角スペースが二つ入ってしまっています。また、バイナリエディタで見たところやはり20(半角スペース)が入っておりました。
|
55
|
+

|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
**ご質問内容②**
|
60
|
+
「ひょっとして、phpタグの前になんかはいってませんかね?」
|
61
|
+
|
62
|
+
⇒確認いたしましたが、PHPタグの前には何も入っておりませんでした。
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
**ご質問内容③**
|
67
|
+
「ファイルをバイナリエディタで開き、ゴミがどういったコードなのか調べるところからですね
|
68
|
+
また、多バイト文字ではなくシングルバイト文字ではどうなるか追記ください」
|
69
|
+
|
70
|
+
⇒上記の通り、バイナリ表示で20,半角スペースが入っておりました。シングルバイト文字でやってみましたが結果は変わらずでした。
|
71
|
+
|
72
|
+
|
73
|
+
**ご質問内容④**
|
74
|
+
「そのファイルがインクルードしたファイルのどこかで <?php の前か?> のあとに空白や改行、タブなどが入っていないか
|
75
|
+
ファイルをBOMつきで保存してないか」
|
76
|
+
|
77
|
+
⇒確認しましたが、そのようなことはありませんでした。
|
78
|
+
|
79
|
+
**ご質問内容⑤**
|
80
|
+
「phpのコードなのに「<?php」が書いていないことから、
|
81
|
+
一連の処理の一部分のコードを切り出したものだと推察します。
|
82
|
+
|
83
|
+
そして、掲載された箇所のコードでは$dataListの初期化が行われていないことが気になります。
|
84
|
+
ですが、すでに何らかのデータが含まれているのであれば
|
85
|
+
「あ」がセルA1の位置に来ない気がするのでしっくりきません。」
|
86
|
+
|
87
|
+
⇒はい、その通りでございます。具体的にはwebアプリケーションのあるコントローラー内の処理になります。$dataListの初期化は書き忘れておりました。
|
88
|
+
|
89
|
+
「文字エンコーディングをUTF-8からSJISに変換したあとにimplodeにかけているの、逆じゃないでしょうか。」
|
90
|
+
|
91
|
+
⇒本当ですね...逆でした。しかしながら、これを逆にして試しましたが結果は変わらずでした...
|
92
|
+
|
93
|
+
|
94
|
+
他に何か解決方法は考えられますでしょうか。
|