Re[2]: [PHP] Invalid byte sequence for encoding UTF-8

From: Date: Fri, 07 Nov 2008 02:20:32 +0000
Subject: Re[2]: [PHP] Invalid byte sequence for encoding UTF-8
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-283043@lists.php.net to get a copy of this message
Greetings, paragasu. In reply to Your message dated Friday, October 31, 2008, 12:39:14, >>> i am using php with postgresql. when i submit post query to the >>> server. i have the pg_exec error >>> <snip> >>> Warning: pg_query() [function.pg-query]: Query failed: ERROR: invalid >>> byte sequence for encoding "UTF8": 0x93 HINT: This error can also >>> happen if the byte sequence does not match the encoding expected by >>> the server, which is controlled by "client_encoding". >>> </snip> >>> is there any function to prevent this type of error. something i can >>> apply to any POST query >>> before i submit to pg_query() ? >> >> You probably need to tell us which functions you are using to create/modify >> the UTF8 string that you are sending as data. I does sound like a conversion >> TO UTF8 is not being carried out somewhere. PHP5 requires that only >> multi-byte >> string functions are used to handle UTF8 data >> > i do not use any function other that addslashes on the $_POST Here is what you're doing wrong. I'm 99% sure you have applied it in wrong place and have your data sent out already destroyed by addslashes. Only 2 places where any escaping should occur: 1. before writing data to storage, use appropriate storage-dependent escaping routine. 2. before sending data to client. Use appropriate encoding routine, such as htmlentites() Don't use add*slashes and any kind of it, including magic_quotes*, unless you surely know what you're doing and why. And please, don't top-post. -- Sincerely Yours, ANR Daemon <anrdaemon@freemail.ru>

« previous php.general (#283043) next »