PHP – Fix apostrophe(‘) converting to entity &#039 in csv export

1) If you read a .csv file for download:

use \xEF\xBB\xBF after headers and just before you echo file data. For example:

echo "\xEF\xBB\xBF"; // UTF-8 BOM
readfile($file);

2) If you echo per line use htmlspecialchars_decode to covert single and double quotes. For example:

echo '"'.htmlspecialchars_decode($val, ENT_QUOTES).'"'.',';

Leave a Reply