Can I safely use PHP string functions with ASCII strings?

Solution:

Do PHP string functions behave the same for ASCII characters regardless of locale?

No, they don’t always. A well-known counterexample is the Turkish dotted-I:


setlocale(LC_CTYPE, "tr_TR");
echo strtoupper('hi!');

Output:

H\xDD! // equivalent to ‘Hİ!’ in ISO-8859-9

This shows that locale can affect even ASCII-range string operations.

✅ Implications:

In some cases, you may need locale-independent string handling.

Reverting the locale to C using setlocale() can be a temporary fix, but it’s not ideal.

The POSIX process-level locale model is poorly suited for modern client/server applications where multiple locales may be needed simultaneously.