note 103843 modified in function.substr by danbrown

From: Date: Fri, 06 May 2011 14:00:12 +0000
Subject: note 103843 modified in function.substr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179487@lists.php.net to get a copy of this message
If you need to parse utf-8 strings char by char, try this one: <?php $utf8marker=chr(128); $count=0; while(isset($string{$count})){ if($string{$count}>=$utf8marker) { $parsechar=substr($string,$count,2); $count+=2; } else { $parsechar=$string{$count}; $count++; } /* do what you like with parsechar ... , eg.:*/ echo $parsechar."<BR>\r\n"; } ?> - it works without mb_substr - it is fast, because it grabs characters based on indexes when possible and avoids any count and split functions --was-- If you need to parse utf-8 strings char by char, try this one: $utf8marker=chr(128); $count=0; while(isset($string{$count})){ if($string{$count}>=$utf8marker) { $parsechar=substr($string,$count,2); $count+=2; } else { $parsechar=$string{$count}; $count++; } /* do what you like with parsechar ... , eg.:*/ echo $parsechar."<BR>\r\n"; } - it works without mb_substr - it is fast, because it grabs characters based on indexes when possible and avoids any count and split functions http://php.net/manual/en/function.substr.php

« previous php.notes (#179487) next »