Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59334 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35426 invoked from network); 3 Apr 2012 01:35:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Apr 2012 01:35:47 -0000 Authentication-Results: pb1.pair.com header.from=charlie@charliesomerville.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=charlie@charliesomerville.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain charliesomerville.com from 209.85.160.42 cause and error) X-PHP-List-Original-Sender: charlie@charliesomerville.com X-Host-Fingerprint: 209.85.160.42 mail-pb0-f42.google.com Received: from [209.85.160.42] ([209.85.160.42:61950] helo=mail-pb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 99/5F-43049-1F35A7F4 for ; Mon, 02 Apr 2012 21:35:46 -0400 Received: by pbcun1 with SMTP id un1so5395548pbc.29 for ; Mon, 02 Apr 2012 18:35:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:message-id:subject:x-mailer:mime-version:content-type :x-gm-message-state; bh=frGAXhzpIz2Uo3FtCskGM/cg1Xe6S9/RWN0ZxEEU/c8=; b=S8rbuMz5ITbk+eOLi14X/g0d5SJvIn8jo6vqbn0FHVOVHAYMyaf6FwC8KTPHbh44bw ww3thwjvRf4ijorPQ1gyRmMd1TcSDyhZdgw2lNmTK5v8xjD1fHmcvCc5TpDbgJxtbONT NRH5kFvbZ4Zfs93oL/mKhVpqKK5dfjOI+NCBrhqqcDrf5eNHMafrl5whPQJmrhCbb066 hu2Ml6aqpf0YmZ+YZhdHdT+nscjHnUCLP9POTrGj2SzXQw4J1H12vrbE0puZRw11oD/I sfaGRWfTpkNNN9wchW9tfL/yBeKCV9c1lVmp0zjxkmugHCnZrFMBgTrGjz4V6xexUfMi I+dA== Received: by 10.68.223.67 with SMTP id qs3mr25265613pbc.142.1333416942313; Mon, 02 Apr 2012 18:35:42 -0700 (PDT) Received: from Envato-Reviewer-2s-iMac.local ([115.146.71.1]) by mx.google.com with ESMTPS id y2sm15140323pbe.67.2012.04.02.18.35.40 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 02 Apr 2012 18:35:41 -0700 (PDT) Date: Tue, 3 Apr 2012 11:35:36 +1000 To: internals@lists.php.net Message-ID: <7EBB3287C8464A93B2B264FDAD2B6756@charliesomerville.com> X-Mailer: sparrow 1.4.2 (build 959.4) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="4f7a53e8_38437fdb_2efd" X-Gm-Message-State: ALoCoQnNhu0pT9kgAYtzVN2B+J1a1nkfkbIyE8J8bHtALzbiOoST+hjQZNAIh1cN777VPEWna7LK Subject: json_encode() and non-UTF8 strings From: charlie@charliesomerville.com (Charlie Somerville) --4f7a53e8_38437fdb_2efd Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi internals, I've created a pull request (https://github.com/php/php-src/pull/33) that changes json_encode to fall back to ASCII for strings that are not valid UTF-8. I ran into an issue in a production application involving PayPal IPN callbacks (which are sent encoded as windows-1252) and json_encode(). If there was an accented character present in the data, json_encode() would fail to encode the string and serialize it as 'null'. I've modified the behaviour of the underlying json_escape_string() implementation to attempt to encode strings anyway while still producing a warning. Thanks -- Charlie Somerville --4f7a53e8_38437fdb_2efd--