mysql - php - utf8 encoding the text twice. Will it have any negative effect? -


this question has answer here:

mysql database returns utf8 encoded text. basically, used pdo attribute mysql_attr_init_command , passed:

set character set utf8 

it returns utf8 encoded text. text in database plain utf8, &alum; returned is.

so need call utf8_encode again in php actual utf8 char. working fine.

i know, if have negative effect encoding text twice or not affect other encoding non-encoded text above?

thanks!

edit:

i using following code right characters:

 $val = utf8_encode(addslashes(html_entity_decode(strip_tags($val)))); 

so convert following text from:

<font color=\"#222222\" face=\"arial, sans-serif\" size=\"2\"> test event  &nbsp; &nbsp;</font><span style=\"color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 13px;\">pers&ouml;nlichkeit universit&auml;t&quot;</span> 

(this text coming database, after calling set character set utf8)

to:

test event persönlichkeit universität\" 

&auml; html entity shouldn't have made database in first place. has nothing utf-8.

if call utf8_encode on "&auml;" nothing happen encoding same iso-8859-1 , utf-8. see character represents in browser because interpreted html.

you should never, normal web app developer, call utf8_encode. don't need iso-8859-1 utf-8 conversion, firstly because browsers , mysql not support it. alias latin1 , iso-8859-1 windows-1252 compatibility. secondly, can cause browsers , database send data in utf-8 utf-8 , no conversion necessary.

you shouldn't convert html entities either - unnecessary because utf-8 can represent characters.

the data in database should not have concern html - data there should canonical authorative as-is representation of data. right there confusion whether data literally meant &auml; or ä causes problems this:

enter image description here

image thedailywtf


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -