News Feed
Sections




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

David Sklar's Blog:
Visiting each character in a string
April 26, 2007 @ 07:01:00

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 sorts of 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).

0 comments voice your opinion now!
string loop utf8 mbstrlen mbsubstr benchmark textiterator string loop utf8 mbstrlen mbsubstr benchmark textiterator


blog comments powered by Disqus

Similar Posts

Ryan Malesevich's Blog: WP Plugins: WP-Chunk

Sameer Borate's Blog: Benchmarking Wordpress SQL using FirePHP

Andrei Zmievski's Blog: All the Little Pieces, or TextIterator in PHP 6

WebDevLogs.com: BREAK the FOR VS WHILE loop war

Felix Geisendorfer's Blog: Enforce utf8 for multiple db connections


Community Events

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


part2 api series example community framework yii2 symfony language list podcast opinion conference composer project application php7 interview laravel introduction

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