Skip to content

strtr.xml Fix the confusing example, CS - #5754

Merged
kamil-tekiela merged 3 commits into
php:masterfrom
mmalferov:patch-2
Aug 11, 2026
Merged

strtr.xml Fix the confusing example, CS#5754
kamil-tekiela merged 3 commits into
php:masterfrom
mmalferov:patch-2

Conversation

@mmalferov

Copy link
Copy Markdown
Member

The first example — with multi-byte characters — seems confusing. The function replaces only the first byte of a multi-byte character å, and the output shows a black diamond with a question mark (U+FFFD).

Instead of a real example, the page actually offers pseudocode, which an unprepared reader has to slog through to finally understand the substitution algorithm: ä → a, å → a, ö → o. I don't know why 🤷‍♂️

The first example — with multi-byte characters — seems confusing. The function replaces only the first byte of a multi-byte character `å`, and the output shows a black diamond with a question mark (U+FFFD).

Instead of a real example, the page actually offers pseudocode, which an unprepared reader has to slog through to finally understand the substitution algorithm: ä → a, å → a, ö → o. I don't know why 🤷‍♂️
Comment thread reference/strings/functions/strtr.xml Outdated
Comment thread reference/strings/functions/strtr.xml Outdated
Comment on lines +161 to +164
echo strtr("baab", "ab", "01"), "\n";
$replace_pairs = ["ab" => "01"];
echo strtr("baab", $replace_pairs);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you removed the broken example from the first one, maybe it would be a good idea to add it here, so that readers see why it doesn't work with multibyte strings and 3-parameter mode. See https://www.php.net/manual/en/function.strtr.php#111270

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look now. Is the example of replacement in a multi‑byte string clear?

@kamil-tekiela kamil-tekiela left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nits

Comment thread reference/strings/functions/strtr.xml Outdated
Comment thread reference/strings/functions/strtr.xml Outdated
Comment thread reference/strings/functions/strtr.xml Outdated
Comment thread reference/strings/functions/strtr.xml Outdated
Comment thread reference/strings/functions/strtr.xml Outdated
Co-authored-by: Kamil Tekiela <tekiela246@gmail.com>
@kamil-tekiela
kamil-tekiela merged commit 1ed1191 into php:master Aug 11, 2026
2 checks passed
@mmalferov
mmalferov deleted the patch-2 branch August 11, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants