PHPDeveloper.orghttp://www.phpdeveloper.org
Up-to-the Minute PHP News, views and communityen-usTue, 31 Mar 2015 15:47:08 -050030http://www.phpdeveloper.org/news/7710http://www.phpdeveloper.org/news/7710
In a new post today, David Skalr demonstrates how he solved a simple problem - looping through all of the characters in a string in a UTF-8 enabled environment.

So I've got this string (in PHP) and I need to scan through it character by character. I can't scan byte by byte because it's 2007, our users write in all sortsof languages, and the string is UTF-8.

To remedy the situation, he falls back on an old standby - the mb_* functions, mb_substr and mb_strlen. His benchmarks show that, with a 1500 character string, running his sample script gives him around 61 scans per second. (The PHP6 version with TextIterator works much faster, though - 450 scans per second).