Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By laden_maiden on
hi everybody, i just have a issue with charset. i have a function in one php file and i make a call in two diferent placesl just for testing purposes. this is my function:
public static function retornar_matriculados_activos_letra($letra){
$conectar = new ConexionDB();
$mysqli = $conectar->abrirConexion();
$sql = "SELECT * FROM matriculado WHERE estado = 'ACTIVO' AND LEFT(apellido, 1)='".$letra."' order by apellido ";
$resultado = $mysqli->query($sql);
while ($row = $resultado->fetch_object()){
$arr[] = array( "apellido" => $row->apellido,
"nombre" => $row->nombre);
}
$mysqli->close();
return $arr;
}
i have a php file in my root server directory where i make the call:
print_r(Matriculado::retornar_matriculados_activos_letra('A'));
and i have created a test form in drupal 7:
function ezequiel_menu() {
$items = array();
$items['ezequiel'] = array(
'title' => t('ezequiel'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ezequiel_form'),
'access callback' => TRUE,
'description' => t('ezequiel'),
'type' =>MENU_CALLBACK,
);
return $items;
}
function ezequiel_form($form, &$form_state) {
print_r((Matriculado::retornar_matriculados_activos_letra('A')));
exit;
$form['nota'] = array(
'#markup' => '',
);
return $form;
}
yep, i know, its just a print_r and exit. but my php file in the root directory returnt ( for example):
[apellido] => ACUÑA
[nombre] => JERE
and the print_r in my module form:
[apellido] => ACU�A
[nombre] => JERE
there is any problem when the function is called trought drupal instead of been called in a external php file? i cant solve it.
thanks!
Comments
When it's printed to the
When it's printed to the screen (not a print_r() dump), it should show correctly. I see the same with Japanese sometimes. print_r() dumps a bunch of gibberish to the screen, but outputting through Drupal shows the proper Japanese characters.
ok , i changed my code just
ok , i changed my code just for drupal print out the info:
unfortunately it keeps showing wrong, what can i check? this happens only in development enviroment. testing and production works fine. but having differences between enviroments brings troubles, so i want to correct it. maybe the whole drupal development installed on my machine is the problem?
i retrieve the data in devel und testing enviroment from the same database, and in testing shows fine but in not in devel, so there is a problem with the drupal instance not with database charsets, i guess...
thanks!
Make sure your php files are
Make sure your php files are saved in UTF8 charset.