Locales are stupid


Item has a rating of 5 (Liked by Adam)
#6885 (In Topic #1815)
Site director
Chris Graham is in the usergroup ‘Administrators’
Here's some simple PHP code…

Code (PHP)


setlocale(LC_ALL, 'tr_TR');

echo strtoupper('i');
echo strtolower('I');

var_dump(preg_match('#TIMMY#i', 'timmy') > 0);

You'd expect it to output Iibool(true).
However, if the Turkish locale is actually installed on a server, you get ��bool(false).

This is because the basic letters 'i' and 'I' don't have the same case conversion in Turkish, and everything is following locale rules.

I'm trying to deal with most of this in v11. It seems a small issue, because you can just turn off case conversion locales for Turkish and nobody is going to really be bothered, case conversion is almost entirely used for coding logic rather than display logic.

However, the real kicker is that locale settings are implemented on a per-process level, and if anyone has PHP installed via the Apache module rather than CGI, any other parallel running request on the server may change the locale during your request and screw it up. Imagine you're on a shared server alongside a Turkish website.

For this reason, the Health Check system in v11 is going to give a warning if a server is using the PHP Apache module.

Become a fan of Composr on Facebook or add me as a friend. Add me on on Twitter. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top
1 guest and 0 members have just viewed this.


Users online:

Philip, gabriel58, babu, deepu_ms, Manu, Paul D, amit.nigam

Forum statistics:
  • 1,298 topics, 5,830 posts, 7,065 members
  • Our newest member is raguragavan
Back to Top