json - PHP utf8_encode with utf8 characters included -
background: part of system uses utf8_encode convert html code utf8 format before passing on json_encode.
problem: fine until entered utf8 characters(chinese) system. noticed mentioned utf8 characters encoded twice , came out garbled.
sidenote: have no experience charset encoding , whatnot until now. perhaps don't need use utf8_encode before json_encode since database , connections set utf8. without chinese characters in html code, mb_detect_encoding return ascii(not iso-8859-1). couldn't through json_encode without returning null... use of utf_8 encode worked until now.
update: solved issue typecasting html code string; via (string)$html; before assigning json_encode().
thanks posted here led me final solution.
i had similar problem. maybe help: try use iconv();
. had problems polish characters (ąężćźłóń etc.) in encodings other utf8 - when used json_encode
, there no output. went fine after using iconv();
. catch is, have know source encoding before proceed. if don't know encoding, use mb_detect_encoding()
@lukas suggested. example:
$content = iconv('iso-8859-2','utf-8', $content); echo json_encode(array('content' => $content));
Comments
Post a Comment