Character encoding is always a little bit tricky in languages with special letters.
MySQL database server is under UTF-8 Unicode (utf8)
the collation is utf8-general-ci
when, using mysqli, i get some data from the database :
while($row = $result->fetch_assoc()){
foreach ($row as $field=>$value){
print(mb_detect_encoding($value).' '.$value."<br/>");
}
}
characters are encoded ASCII not UTF-8. Where does it come from ?
More infos : My Apache AddDefaultCharset is utf-8
the encoding charset for the html page is utf-8
I build the database with a script exported from another database which is utf-8 too
PS : I tried the mysqli_set_charset($mysqli, "utf8") but it does not change anything.
I really would like to know when and how the data is encoded ASCII ?
Thank you
PS 2 : this is the result I have with the mb_detect_encoding
ASCII ESSAI
ASCII 34
ASCII Bonjour
ASCII 41
UTF-8 ���������������
and the warning from DOMElement : Warning: DOMElement::setAttribute() [domelement.setattribute]: string is not in UTF-8
PS 3 : the problem is with the UTF-8 data.
In the database I have èèèèèèèèèèèèèèèèèèèèè
if I use utf8_encode around the string, I have no more problem and this as a result :
ASCII ESSAI
ASCII 34
ASCII Bonjour
ASCII 41
UTF-8 èèèèèèèèèèèèèèè
ASCII 43
So obviously my utf8 string is a utf8 string (see mb_detect_encoding) but the value has been changed somehow
var_dump()the string and add it to your question.