Skip to content

mb_check_encoding is detecting SJIS as Windows-1252 in PHP 8.1 #13746

Open
@rtio

Description

@rtio

Description

Works as expected in 7.4

The following code:

<?php

$string = mb_convert_encoding('パーティーへ行かないか', 'SJIS', 'UTF-8');

var_dump(mb_check_encoding($string, 'SJIS')); // should be valid
var_dump(mb_check_encoding($string, 'Windows-1252')); // should be invalid

var_dump(mb_detect_encoding($string, 'SJIS', true)); // should be valid
var_dump(mb_detect_encoding($string, 'Windows-1252', true)); // should be invalid

var_dump(mb_convert_encoding($string, 'UTF-8', 'SJIS')); // should be correct
var_dump(mb_convert_encoding($string, 'UTF-8', 'Windows-1252')); // should be wrong

Resulted in this output:

bool(true)
bool(true)
string(4) "SJIS"
string(12) "Windows-1252"
string(33) "パーティーへ行かないか"
string(43) "ƒp�[ƒeƒB�[‚Ö�s‚©‚È‚¢‚©"

But I expected this output instead:

bool(true)
bool(false)
string(4) "SJIS"
bool(false)
string(33) "パーティーへ行かないか"
string(46) "ƒp�[ƒeƒB�[‚Ö�s‚©‚È‚¢‚©"

Online example here

PHP Version

PHP 8.1.27

Operating System

CentOS 7

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions