Skip to content

Instantly share code, notes, and snippets.

@caugner
Created March 18, 2019 13:52
Show Gist options
  • Save caugner/b274b3a49cb64a586bfb43e8d46724eb to your computer and use it in GitHub Desktop.
Save caugner/b274b3a49cb64a586bfb43e8d46724eb to your computer and use it in GitHub Desktop.
php: mb_detect_encoding returns false for chr(128..193) and chr(245..255)
<?php
for ($i = 0; $i <= 255; $i++) {
printf("%d:%s\n", $i, mb_detect_encoding(chr($i)));
}
/**
Output:
0:'ASCII'
1:'UTF-8'
2:'UTF-8'
3:'UTF-8'
4:'UTF-8'
5:'UTF-8'
6:'UTF-8'
7:'UTF-8'
8:'UTF-8'
9:'ASCII'
10:'ASCII'
11:'UTF-8'
12:'UTF-8'
13:'ASCII'
14:'UTF-8'
15:'UTF-8'
16:'UTF-8'
17:'UTF-8'
18:'UTF-8'
19:'UTF-8'
20:'UTF-8'
21:'UTF-8'
22:'UTF-8'
23:'UTF-8'
24:'UTF-8'
25:'UTF-8'
26:'UTF-8'
27:'UTF-8'
28:'UTF-8'
29:'UTF-8'
30:'UTF-8'
31:'UTF-8'
32:'ASCII'
33:'ASCII'
34:'ASCII'
35:'ASCII'
36:'ASCII'
37:'ASCII'
38:'ASCII'
39:'ASCII'
40:'ASCII'
41:'ASCII'
42:'ASCII'
43:'ASCII'
44:'ASCII'
45:'ASCII'
46:'ASCII'
47:'ASCII'
48:'ASCII'
49:'ASCII'
50:'ASCII'
51:'ASCII'
52:'ASCII'
53:'ASCII'
54:'ASCII'
55:'ASCII'
56:'ASCII'
57:'ASCII'
58:'ASCII'
59:'ASCII'
60:'ASCII'
61:'ASCII'
62:'ASCII'
63:'ASCII'
64:'ASCII'
65:'ASCII'
66:'ASCII'
67:'ASCII'
68:'ASCII'
69:'ASCII'
70:'ASCII'
71:'ASCII'
72:'ASCII'
73:'ASCII'
74:'ASCII'
75:'ASCII'
76:'ASCII'
77:'ASCII'
78:'ASCII'
79:'ASCII'
80:'ASCII'
81:'ASCII'
82:'ASCII'
83:'ASCII'
84:'ASCII'
85:'ASCII'
86:'ASCII'
87:'ASCII'
88:'ASCII'
89:'ASCII'
90:'ASCII'
91:'ASCII'
92:'ASCII'
93:'ASCII'
94:'ASCII'
95:'ASCII'
96:'ASCII'
97:'ASCII'
98:'ASCII'
99:'ASCII'
100:'ASCII'
101:'ASCII'
102:'ASCII'
103:'ASCII'
104:'ASCII'
105:'ASCII'
106:'ASCII'
107:'ASCII'
108:'ASCII'
109:'ASCII'
110:'ASCII'
111:'ASCII'
112:'ASCII'
113:'ASCII'
114:'ASCII'
115:'ASCII'
116:'ASCII'
117:'ASCII'
118:'ASCII'
119:'ASCII'
120:'ASCII'
121:'ASCII'
122:'ASCII'
123:'ASCII'
124:'ASCII'
125:'ASCII'
126:'ASCII'
127:'ASCII'
128:false
129:false
130:false
131:false
132:false
133:false
134:false
135:false
136:false
137:false
138:false
139:false
140:false
141:false
142:false
143:false
144:false
145:false
146:false
147:false
148:false
149:false
150:false
151:false
152:false
153:false
154:false
155:false
156:false
157:false
158:false
159:false
160:false
161:false
162:false
163:false
164:false
165:false
166:false
167:false
168:false
169:false
170:false
171:false
172:false
173:false
174:false
175:false
176:false
177:false
178:false
179:false
180:false
181:false
182:false
183:false
184:false
185:false
186:false
187:false
188:false
189:false
190:false
191:false
192:false
193:false
194:'UTF-8'
195:'UTF-8'
196:'UTF-8'
197:'UTF-8'
198:'UTF-8'
199:'UTF-8'
200:'UTF-8'
201:'UTF-8'
202:'UTF-8'
203:'UTF-8'
204:'UTF-8'
205:'UTF-8'
206:'UTF-8'
207:'UTF-8'
208:'UTF-8'
209:'UTF-8'
210:'UTF-8'
211:'UTF-8'
212:'UTF-8'
213:'UTF-8'
214:'UTF-8'
215:'UTF-8'
216:'UTF-8'
217:'UTF-8'
218:'UTF-8'
219:'UTF-8'
220:'UTF-8'
221:'UTF-8'
222:'UTF-8'
223:'UTF-8'
224:'UTF-8'
225:'UTF-8'
226:'UTF-8'
227:'UTF-8'
228:'UTF-8'
229:'UTF-8'
230:'UTF-8'
231:'UTF-8'
232:'UTF-8'
233:'UTF-8'
234:'UTF-8'
235:'UTF-8'
236:'UTF-8'
237:'UTF-8'
238:'UTF-8'
239:'UTF-8'
240:'UTF-8'
241:'UTF-8'
242:'UTF-8'
243:'UTF-8'
244:'UTF-8'
245:false
246:false
247:false
248:false
249:false
250:false
251:false
252:false
253:false
254:false
255:false
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment