shingala sohil shingala sohil - 1 year ago 74
PHP Question

array create issue with german language

I have database in german language. I am fetching data from database and create array. problem is some german characters are converted special character. thats why not able to encode array in json. i have also tried by putting header for german language but it is for display purpose so it is not works.

please check below array created

enter image description here

if i copy and paste that same string manually and create array than it create perfect array. can you please solve issue.

enter image description here

after use of

htmlentities($str, ENT_QUOTES, 'UTF-8', false);

enter image description here

you can see have display both string one is fetched from database and one is encoded using htmlentities. you can see last index of array is empty so htmlentities could not encode it.

Answer Source

You need to escape your string. Try this:

// $str, encode quotes, UTF-8 encoding, false (do not double encode).
echo htmlentities($str, ENT_QUOTES, 'UTF-8', false);

Replace $str with your string. This should fix your issue.