[wp-hackers] Escaping post meta values
otto at ottodestruct.com
Wed May 22 20:52:18 UTC 2013
On Wed, May 22, 2013 at 3:15 PM, Justas Butkus <jbutkus at time.ly> wrote:
> On the other hand - due to this it's performance is not that good, when
> comparing with `json_encode()`, for example, when serializing rather simple
> structures (lists, hashes, etc.).
Tests show that serialize is faster for most common data. json_encode
doesn't catch up until the data gets large. Too large to store as
for some numbers and graphs and so forth.
On Wed, May 22, 2013 at 3:19 PM, Dan Phiffer <dan at phiffer.org> wrote:
> But I'm running into a new problem that when I pass objects straight into update_post_meta() it seems that whenever the data structure includes Emoji characters it results in a postmeta string that comes out empty from get_post_meta(). Is there a known workaround for this?
The json_encode function does have the advantage that it encodes UTF-8
characters into escape sequences and back, while serialize does not.
The serialize/unserialize functions also are non-forgiving of
malformed data, while json is quite forgiving. And depending on the
underlying MySQL version, character set, etc, it's possible that the
data being stored gets munged up by MySQL and thus doesn't get stored
properly (or undergoes a character set conversion), and so when you
get it back, the unserialize fails, and you get nothing.
This is indeed a problem. There is not a "good" workaround that I know
of. You could try using iconv() to convert the problem data to a
different character set before passing it to the meta functions.
Converting problem strings from UTF-8 to ISO-8859-1 has worked for me
in the past.
More information about the wp-hackers