php / php/doc-en

Add an example for locale collation strength in grapheme_strpos()

Open Beginner friendly
#5,560 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Affected page

https://www.php.net/manual/en/function.grapheme-strpos.php

Current issue

The grapheme_strpos() documentation includes a locale parameter, but the
documentation does not show that the locale may include Unicode locale
extension keys.

In particular, users may not realize that the Unicode locale extension key
ks can be used to request a collation strength, such as
en_US-u-ks-identic.

Suggested improvement

Expand the description of the locale parameter and add an example showing
that ks-identic affects matching.

Suggested wording for the locale parameter:

Locale to use for matching. The locale may include Unicode locale extension
keys, such as `ks` for collation strength.

Also consider adding a reference to Collator::setStrength() for users who
need to understand collation strength levels.

Example:

<?php

$textStyle = "\u{263A}\u{FE0E}";  // text presentation
$emojiStyle = "\u{263A}\u{FE0F}"; // emoji presentation

var_dump(grapheme_strpos($textStyle, $emojiStyle));

var_dump(grapheme_strpos(
    $textStyle,
    $emojiStyle,
    locale: 'en_US-u-ks-identic'
));

Expected output:

int(0)
bool(false)

Without identical strength, the two variation selector sequences match. With
en_US-u-ks-identic, the variation selectors are significant, so the search
does not match.

Additional context (optional)

The addition of the locale parameter makes grapheme_strpos() closer to
ICU collation-based matching.

Collator::compare() is appropriate when comparing two complete strings.
grapheme_strpos() is appropriate when searching for a substring and
returning its position in grapheme units.

Since collation strength affects matching, Collator::setStrength() is a
useful reference for understanding values such as primary, secondary,
tertiary, quaternary, and identical strength.

Collator::setStrength
https://www.php.net/manual/en/collator.setstrength.php
Specification reference:
https://www.unicode.org/reports/tr35/dev/tr35-collation.html#Setting_Options

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

Open the affected grapheme_strpos() manual page and start with the locale parameter description and its existing examples. Explain Unicode locale extension keys such as ks, add the supplied ks-identic example and expected output, and consider linking Collator::setStrength() so the documentation clearly shows the completed behavior.

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
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.