. Updated Daily. Editions SDA India   SDA Indonesia
JAX Asia 2008 - Conference for Enterprise Java, SOA, Spring, Web Services, Ajax, Agile and more
BUSINESS ENTERPRISE SOLUTIONS ARCHITECTURE INFORMATION SECURITY WIRELESS & MOBILITY DATA & STORAGE DEVELOPMENT HARDWARE













News

Thursday, 26 April 2007

Article: Learn How to Visit Each Character in a String

 

 

Ever wondered of a way to get a string in PHP scanned character by character? David Sklar shows you some examples to carry out this procedure.

The PHP 5 solution uses mb_strlen() to find the length and then mb_substr() to grab each character, he says. He gives you a code example to facilitate the process and also adds an example to do it in PHP 6.

He further adds that some rough benchmarks on a 1500 character and 2900 byte string gave him about 61 scans/sec with PHP 5.2.1, when a 'scan' is just moving through the loop above with mb_substr and doing one if() test comparing the char to '>'

Under PHP 6.0.0-dev with unicode.semantics=on, switching from mb_strlen() and mb_substr() to regular strlen() and substr() produces about the same result. The indexing with [] is the same speed as substr(), he initiates.

However, the TextIterator case is much faster, about 450 scans/sec he concludes.

 

Read the Post

 
 
print save email comment

print

save

email

comment

 
 

Search SDA Asia

Free eNewsletter

SDA Asia Magazine Free Download
 
 
 
Copyright @ 2008 SDA Asia Magazine - All Right Reserved Privacy Policy | Terms of Use