NYCPHP Meetup

[nycphp-talk] iterating through a multibyte string

Rob Marscher rmarscher at beaffinitive.com
Wed Jan 13 13:42:24 EST 2010


On Jan 13, 2010, at 12:44 PM, John Campbell wrote:
> You forgot
> mb_internal_encoding("UTF-8");
> 
> without that, mb_substr is just an alias for substr

Thanks, John.  I thought I had that set in my php.ini - but I must have overwritten my php.ini with a new install since then.  

> my results look like:
> 
> normal iteration took 0.64724087715149
> mb_substr method took 16.471849918365
> mb_substr method with shortening the string took 21.613878965378
> preg_split method took 1.927277803421
> 
> Dan is the winner.  preg_split always runs in linear time.  Both of
> the mb_substr are O(N^2), because the first step in mb_substr is
> splitting the string into array.  It is not as intelligent as I
> initially assumed.

Thanks for the analysis!  I got similar results on the new run too.




More information about the talk mailing list