News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Evert Pot's Blog:
basename() is locale-aware
March 30, 2010 @ 12:04:35

Evert Pot found out an interesting thing about the basename function in PHP - it's more than just a handy shortcut for paths, it's also locale aware.

It turns out basename does a bit more than just splicing the string at the last slash, because it's locale aware. In my case I was dealing with a multi-byte UTF-8 string. It took me quite some time figuring out what was going on, because I was testing from the console which had the en_US.UTF-8 locale, and the bug was appearing on Apache, which defaults to the C locale.

He includes an example snippet of code showing how it can work with both the default (well, for Apache anyway) of the "C" locale versus the "UTF-8" locale and return different results for the same urldecoded information.

2 comments voice your opinion now!
basename locale utf8 urldecode


blog comments powered by Disqus

Similar Posts

Edd Mann: Reversing a Unicode String in PHP using UTF-16BE/LE

Three Devs & A Maybe Podcast: Understanding Character Sets and Encodings

Evert Pot's Blog: basename() is locale-aware

Evert Pot's Blog: basename() is locale-aware

SitePoint PHP Blog: Hot PHP UTF-8 tips


Community Events





Don't see your event here?
Let us know!


list introduction developer refactor series install framework interview testing wordpress threedevsandamaybe unittest configure language opinion code podcast community laravel release

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework