PHP Escaped special characters to html -


i have string looks "v\u00e4lkommen till mig" after doing utf8_encode() on string.

i string become

 välkommen till mig 

where character

  \u00e4 = ä = ä 

how can achive in php?

  • do not use utf8_(de|en)code. converts utf8 iso-8859-1 , back. iso 8859-1 not provide same characters iso-8859-15 or windows1252, used encodings (besides utf-8). better use mb_convert_encoding.

  • "v\u00e4lkommen till mig" > string looks json encoded string utf8 encoded. unicode code positiotion of "ä" u+00e4 >> \u00e4.

example

<?php header('content-type: text/html; charset=utf-8'); $json = '"v\u00e4lkommen till mig"'; var_dump(json_decode($json)); //it return utf8 encoded string "välkommen till mig" 

what source of string?

there no need replace ä html representation &auml;, if print in utf8 encoded document , tell browser used encoding. if necessary, use htmlentities:

<?php $json = '"v\u00e4lkommen till mig"'; $string = json_decode($json); echo htmlentities($string, ent_compat, 'utf-8'); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -