php / php/doc-en

mb_detect_encoding() et al. need sufficient input

Open
#1,730 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Extension: mbstring
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

Description

The following code:

<?php
$strings = ['bl', 'Bl', 'Blog'];
foreach ($strings as &$str)  {
    $str = mb_convert_encoding($str, 'UTF-8', mb_list_encodings());
}
echo '<pre>' . print_r($strings, true) . '</pre>';

Resulted in this output:

Array
(
    [0] => 扬
    [1] => 求
    [2] => 求杯
)

But I expected this output instead:

Array
(
    [0] => bl
    [1] => Bl
    [2] => Blog
)
PHP Version

PHP 8.1.8

Operating System

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PHP documentation entries for mb_detect_encoding() and mb_convert_encoding(), then review the behavior shown by the reproducible example. Document the requirement for sufficient input and the resulting limitations or misleading conversions, with wording that explains why the expected strings are not preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.