Dynamic Flash

Confessions of a serial code abuser
  • rss
  • Home
  • MTASC
  • Archives
  • About me
  • Goodies
    • Base64 encoder/decoder class
  • My Bookshelf
  • My Talks

PHP, preg_split() and utf-8

Sunday, 20 November 2005

This is just a quickie for anyone who's battling with the UTF-8 support (or lack thereof) in PHP4.

According to the online docs the PCRE family of functions can be made UTF-8 aware by adding a u modifier to the pattern you're using. Since the standard explode function doesn't support UTF-8, you might think of using the preg_split function like this to split a UTF-8 string into an array of characters:

PLAIN TEXT
PHP:
  1. $characters = preg_split('//u', $source);

Unfortunately it seems that preg_split is the only PCRE function that doesn't support the u modifier. Instead, you'll have to use preg_match_all like this to get the same effect:

PLAIN TEXT
PHP:
  1. preg_match_all('/./u', $source, $matches);
  2. $characters = $matches[0];

Categories
PHP
Comments rss
Comments rss
Trackback
Trackback

« IFBIN: Good, bad or ugly? Native-looking widgets in Flash »

2 responses

That helped me, thanks.

JL | Tuesday, 21 February 2006 | 6:33 pm

That helped me, thanks.

Thanks for this! You saved me from getting crazy!!!

Fabio Varesano | Tuesday, 23 October 2007 | 12:00 pm

Thanks for this! You saved me from getting crazy!!!

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

About Dynamic Flash

Steve Webster is a Senior Web Developer for Yahoo! in London, UK.

He is more than a little concerned that he defines himself in terms of his career, and that he talks about himself in the third person.

Find out more

Recent Posts

  • Read and write local files with Flash Player 10
  • The problem with SproutCore
  • Yahoo! London seeks Junior Developers
  • I am Singularity
  • Yahoo! Astra component library 1.1 released

Tags

Accessibility ActionScript actionscript3 actionscript 3.0 air apple astro book conference designer filereference file upload Flash flex framework internet internet explorer JavaScript jobs junior microsoft opportunities ria singularity08 skin tutorial urlrequest web developer web development Web Standards Yahoo!

del.icio.us-ed

Stuff

Singularity?
Flex.org - The Directory for Flex
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox