PDA

View Full Version : Unicode/UTF-8 and PHP and a possible solution?


mulligan
6th May 2007, 09:56 PM
In an ordinary PHP editor if I paste unicode characters into it they show up as ????

So to try and get round this I open whatever PHP file Im working on in notepad, insert whatever unicode I want into the file and then save the file using the unicode or utf-8 encoding.

To force it to save as a PHP file I just enclose the file name in "double quotes" so it would I look type something like "template.php" into the File Name box

This seems to work but do any of you experts know if this is Ok to do or is it likely to cause problems somewhere down the line?

(I haven't had any problems so far)

Or is there a unicode compliant PHP editor available or does PHP and unicode just not mix well?

(I am totally new to PHP so any input is welcome)

clipper
6th May 2007, 10:43 PM
Any text editor that can save as UTF-8 should work. You shouldn't need to use the quotes, just use .php as the extension in the filename. I use notepad2 (http://www.flos-freeware.ch/notepad2.html), which gives you basic html syntax markers and numbers each line.

In an ordinary PHP editor if I paste unicode characters into it they show up as ????

Also, I don't know about a php editor, but in Adobe Golive the unicode characters come up as ???? if you paste them into the layout (or preview) mode. When you paste the text into the source code it shows up fine.

xxbossmanxx
6th May 2007, 10:57 PM
It's all good if your server is running mbstring

jacksonm
6th May 2007, 11:02 PM
PHP has fairly poor multi-byte character support. Getting it working properly involves a bit of black magic.


I got it working by adding these lines in php.ini


[mbstring]

mbstring.language = Neutral
mbstring.internal_encoding = UTF-8
mbstring.encoding_translation = On
mbstring.http_input = auto
mbstring.http_output = UTF-8
mbstring.detect_order = auto
mbstring.substitute_character = none;
mbstring.func_overload = 0
mbstring.strict_encoding = On



This, of course, assumes that you have the PHP mbstring module installed. On linux, it looks like this:

# rpm -qa | grep -i mbstring
php-mbstring-5.1.6-3.4.fc6


.

mdw
7th May 2007, 12:57 AM
Never had any trouble - and I use standard builds starting at PHP 4.3x and higher.
MySQL, well that's another story. But really no matter where you host these days you should have no problems; if you do then move.

jacksonm
7th May 2007, 10:09 AM
Never had any trouble - and I use standard builds starting at PHP 4.3x and higher.
MySQL, well that's another story. But really no matter where you host these days you should have no problems; if you do then move.


The php-mysql driver doesn't handle multi-byte well at all; it was completely unsupported even 6 months ago, and the support was added very recently - still buggy as all hell. I tried for a day to get it working, no cigar. I tried it with postgres, which I should have done to begin with, and it worked fine after I added the above configuration to the php.ini.

.