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:

[php] $characters = preg_split(’//u’, $source); [/php]

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:

[php] preg_match_all(’/./u’, $source, $matches); $characters = $matches[0]; [/php]

Categories
PHP

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

4 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!!!

Yet another "thank you"

Sergey | Thursday, 21 May 2009 | 2:13 pm

Yet another “thank you”

Interesting. This works for me. Does it not

Trevor | Saturday, 19 September 2009 | 1:39 am

Interesting. This works for me. Does it not work for you?

$chars = preg_split(’//u’,$unistr);

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

del.icio.us-ed

  • samuel's squawk at master - GitHub
  • Pixelwave - A native 2D iPhone framework, based on the Flash API
  • Pixelwave - A native 2D iPhone framework, based on the Flash API
  • mnot’s Weblog: Are Resource Packages a Good Idea?
  • Download details: IE App Compat VHD
  • ZSync
  • jQuery source viewer
  • Penetration testing tools - Stack Overflow
  • Logrep
  • DOM Window (jquery.DOMWindow.js)

Recent Posts

  • Moving on
  • iPhone / iPod Touch Development Resources
  • Upgrading your app to AIR 1.5
  • Motivate yourself by doing it in public
  • The trouble with Flash and REST
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox