All contributions

thephpleague/uri-src

League URI

A set of PHP libraries for working with URIs and URI templates.

Language
PHP
GitHub stars
51
Merged changes
1
Project site
uri.thephpleague.com

What we changed

The {var:N} prefix modifier in URI templates counts characters instead of bytes and no longer splits multibyte characters.

What this work shows

  • RFC 6570 URI templates
  • UTF-8 and mbstring in PHP
  • Percent-encoding in URLs
What was broken

{?currency:1} cut the euro sign in half

Operator::inject() applied the prefix modifier with substr(), which counts bytes. The euro sign takes three bytes in UTF-8, so the template {?currency:1} with the value €uro gave ?currency=%E2, a fragment that is not valid UTF-8 once decoded.

How we fixed it

The prefix counts characters

The prefix is now taken with mb_substr() and an explicit UTF-8 encoding, as section 2.4.1 of RFC 6570 requires, so the result does not depend on the application's mbstring settings. The multibyte cases from the RFC 6570 conformance suite bundled with the project now pass as well.

#192

Merged change 1

  1. #192 Fix multibyte characters being split by the URI Template prefix modifier Merged 6 September 2026

What it taught us

An RFC has to be read literally: RFC 6570 counts the prefix in characters while PHP's substr() counts bytes, so any non-ASCII character, Polish letters included, could be cut in half.

More about this technology: PHP

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.