1.2.75. Avoid mb_dectect_encoding()

mb_dectect_encoding() is bad at guessing encoding.

For example, UTF-8 and ISO-8859-1 share some common characters : when a string is build with them it is impossible to differentiate the actual encoding.

<?php

$encoding = mb_encoding_detect($_GET['name']);

?>

See also mb_encoding_detect, PHP vs. The Developer: Encoding Character Sets and DPC2019: Of representation and interpretation: A unified theory - Arnout Boks.

1.2.75.1. Suggestions

  • Store and transmit the data format

1.2.75.2. Specs

Short name

Php/AvoidMbDectectEncoding

Rulesets

All, Analyze, Changed Behavior

Exakat since

1.8.9

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Features

mbstring

Available in

Entreprise Edition, Exakat Cloud