1
I did an update on php
on the server and identified that they were not being coded in the standard utf-8
, the first thing I checked was the connection class I use, which in this case is adodb
.
In my connection I perform a process of converting the columns that are in another format to utf-8
in this way:
$dados[$i] = mb_convert_encoding($dados[$i],"UTF-8");
In the php 5.2
was working normally, after updating to the php 5.6.9
he "stopped working," I checked his documentation is the same is not depreciated.
To solve the problem I used the utf8_encode
, thus:
$dados[$i] = utf8_encode($dados[$i]);
Detail, I use adodb + firebird
.
Doubts:
1° What is the difference of these functions, and why mb_convert_encoding
not working anymore.
2° The return of my database is on ASCII
it is possible to simplify this issue of codification utf-8
forASCII
and ASCII
for utf-8
?
Man php.ini
comes set by default
default_charset = "UTF-8" // linha 680
Testing:
$f[$i] = mb_detect_encoding($f[$i]); // ASCII
$f[$i] = mb_convert_encoding($f[$i], "HTML-ENTITIES", "UTF-8");
SUÉLLEM // Entrada
SU�LLEM // Saida
$f[$i] = mb_convert_encoding($f[$i], "ISO-8859-1", "UTF-8");
SUÉLLEM // Entrada
SU?LLEM // Saida
$f[$i] = mb_convert_encoding($f[$i], 'UTF-8', 'ISO-8859-1');
SUÉLLEM // Entrada
SUÉLLEM // Saida
In the third test it works, how strange!
Example of the method _fetch
of adodb
:
function _fetch() {
$f = @ibase_fetch_row($this - > _queryID);
if ($f === false) {
$this - > fields = false;
return false;
}
// OPN stuff start - optimized
// fix missing nulls and decode blobs automatically
global $ADODB_ANSI_PADDING_OFF;
//$ADODB_ANSI_PADDING_OFF=1;
$rtrim = !empty($ADODB_ANSI_PADDING_OFF);
for ($i = 0, $max = $this - > _numOfFields; $i < $max; $i++) {
if ($this - > _cacheType[$i] == "BLOB") {
if (isset($f[$i])) {
$f[$i] = $this - > connection - > _BlobDecode($f[$i]);
} else {
$f[$i] = null;
}
} else {
if (!isset($f[$i])) {
$f[$i] = null;
} else if ($rtrim && is_string($f[$i])) {
$f[$i] = rtrim($f[$i]);
}
}
$f[$i] = utf8_encode($f[$i]);
}
// OPN stuff end
$this - > fields = $f;
if ($this - > fetchMode == ADODB_FETCH_ASSOC) {
$this - > fields = $this - > GetRowAssoc(ADODB_ASSOC_CASE);
} else if ($this - > fetchMode == ADODB_FETCH_BOTH) {
$this - > fields = array_merge($this - > fields, $this - > GetRowAssoc(ADODB_ASSOC_CASE));
}
return true;
}
your answer is insufficient by the question presented, you could add something like why the php update affected the functioning of mb_convert_enconding and the same is not depreciated?
– Gabriel Rodrigues
I even agree about adding more information, but how much the update that affected the functioning I am not aware, and this was also not requested in the question
– Wallace Maxters
was asked yes, 1° question.
– Gabriel Rodrigues
Ah, but he said "it’s not working". And maybe that statement isn’t even correct
– Wallace Maxters
I’ll answer that here, wait, wait. rsrsrsrs
– Wallace Maxters
I also did not understand why, I’m with two versions of php. a 5.2 that transforms ASCII to UTF8 with mb_convert_enconding, is a 5.6 that does not, I just changed the version, so I had to use the utf8_encode that ASCII for UTF8, strange!
– Gabriel Rodrigues
I still don’t understand why it doesn’t work like before, but I already have a solution that works for both versions. thank you. these tests helped a lot.
– Gabriel Rodrigues