When I save "Ben and Jerry's" to my database, and later recall it from the database, into an input tag (so I can edit/resave it), I get
Ben & Jerry's
Where am I going wrong? (Notice that the "&" is correctly translated, but the apostraphe is not). Let me summarise what I am doing...
My web pages have
<meta charset="utf-8" />
and my server dispenses JSON data via PHP and
header('content-type: application/json; charset=utf-8');
My web form, using javascript/jquery, pre-post, pushes all form data thru
encodeURIComponent()
My PHP server code reads the data and pre-db-insert uses
filter_var() and FILTER_SANITIZE_STRING
My mysql db created with "utf8 - default collation" and my insert writes
Ben & Jerry's
Later.... I do a mysql select, and I thought I need only javascript call
decodeURIComponent()
to convert everything back to "Ben & Jerry's" but this appears not to be the case.
What am I missing?
Based on the comments above, and the two links below, I went with prepared statements. I had avoided such until now because of inexperience - I write old school procedure code and most examples given on the php.net page have moved from that style. I hope something here and above helps others...
http://php.net/manual/en/pdo.prepared-statements.php
Thanks everyone