Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
mb_convert_encodingとmb_convert_variablesのautoが違う
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
てきめん tekimen
PRO
April 12, 2023
Programming
720
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
mb_convert_encodingとmb_convert_variablesのautoが違う
#phpstudy 2023年4月12日
てきめん tekimen
PRO
April 12, 2023
More Decks by てきめん tekimen
See All by てきめん tekimen
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
1k
ChatGPTを使ってRaspberry Pi Picoの処理系を書いた
youkidearitai
PRO
0
120
PHP Internals わいわい #3 PIEを使ってみよう
youkidearitai
PRO
0
110
grapheme_strrev関数が採択されました(あと雑感)
youkidearitai
PRO
1
450
Limit of code point for grapheme cluster in programming language side.
youkidearitai
PRO
0
130
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
2
3.9k
PHP 8.5の裏話
youkidearitai
PRO
0
180
CJK and Unicode From a PHP Committer
youkidearitai
PRO
0
510
PHP Internals わいわい #3 mb_*関数を作ってみよう
youkidearitai
PRO
0
180
Other Decks in Programming
See All in Programming
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
220
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
380
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
430
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
0
1.3k
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
180
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
430
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
290
ActionController meets Protocol Buffers
sorah
0
530
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
190
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Test your architecture with Archunit
thirion
2
2.4k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
Between Models and Reality
mayunak
4
500
My Coaching Mixtape
mlcsv
0
360
Designing for Timeless Needs
cassininazir
1
530
The SEO identity crisis: Don't let AI make you average
varn
0
590
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Transcript
mb_convert_encodingと mb_convert_variablesのautoが 違う
自己紹介 てきめん • https://tekitoh-memdhoi.info • @youkidearitai • https://www.youtube.com/use r/tekitohmrp •
https://www.nicovideo.jp/user /2957748 • https://github.com/youkideari tai • オレ
早速見ていきましょう https://3v4l.org/tadVr
違いますね • 何ならエラーメッセージすら違いますね – mb_convert_variables(): Unable to detect encoding –
mb_convert_encoding(): Unable to detect character encoding
mb_convert_encodingのマニュアル • string を解釈するのに使われている 現在の文字 エンコーディング。 配列またはカンマ区切りの文字 列とすることで、 複数のエンコーディングを指定で きます。
この場合、正しいエンコーディングを mb_detect_encoding() と同じアルゴリズムで推 測します。 https://www.php.net/mb_convert_encoding
mb_convert_variablesのマニュアル • from_encoding には配列またはカンマ区切りの文 字列を指定し、 from-coding からエンコーディング の検出を試みます。 from_encoding が省略された
場合、detect_order を使用します。 なんか説明が違う https://www.php.net/mb_convert_variables
よくわからないので、php-srcの奥深くへと入っていく ことにした
mb_convert_encodingでは • $from_encodingに”auto”を指定した時、この関 数にやってくる – mb_detect_encodingと同じ関数を使っている
mb_convert_variablesでは • 何やら違う自動判定が 始まった – マニュアルによると「エ ンコーディング検出の ために Array または
Object の文字列を結 合します。」とある
とりあえず、違うことはわかりました • なるべく”auto”は使わないでくださいね – 使ってる文字コードはわかるようにしておきましょう – というか、2023年現在新たに使う人がいるのだろうか? – となると既存システムだよね多分となる
もうちょっと深ぼっていく 何故かSJISに変換できている mb_detect_orderにSJISが載っていないのに https://3v4l.org/CtI1k
なんでこれに気がついたの • Major overhaul of mbstring (part 33)にて気づく – PHP
8.2まででは(mb_detect_order関係なし に)mb_detect_encodingが一番近いエンコーディングを返 すようにしてた – PHP 8.3ではmb_detect_orderに沿ったリストに基づいて変 換されるようになる – なので、PHP 8.3にアップグレードしようとする未来の人々は気 をつけてね(一応UPGRADINGファイルにも記述してもらった)
もうちょい • mbstring.strict_detectionオプションを1にする ことで、厳密な検出ができるようになる – どっちにしても使わないほうが良いです – 繰り返しますが、使っている文字コードはわかっているよ うにしましょう •
今だったらほとんどUTF-8でいい(はず)
おわり ご清聴ありがとうございました