显示我有一个MySQL数据库与西班牙语的单词,例如像andreá口音。重音未与htmlspecialchars()和使用mysqli
我使用这一点,它显示罚款:
<?php
include "../BD/conexion.php";
mysql_query('SET NAMES utf8');
class Faq
{
public $pregunta;
public $respuesta;
public function __construct($pregunta,$respuesta)
{
$this->pregunta = $pregunta;
$this->respuesta = $respuesta;
}
public static function get()
{
$rows = array();
$res = mysql_query('SELECT * FROM Faq');
while ($row = mysql_fetch_array($res)) {
$rows[] = $row;
}
function filter(&$value) {
$value = htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
array_walk_recursive($rows, "filter");
return $rows;
}
当我在HTML打印排它显示精细,像这样:
但我试图改变新的mysqli_功能如下:
<?php
$conexion = mysqli_connect("localhost","root","","prueba2");
mysqli_query($conexion,'SET NAMES utf8');
mysqli_close($conexion);
class Faq
{
public $pregunta;
public $respuesta;
public function __construct($pregunta,$respuesta)
{
$this->pregunta = $pregunta;
$this->respuesta = $respuesta;
}
public static function get()
{
$conexion = mysqli_connect("localhost","root","","prueba2");
$rows = array();
$res = mysqli_query($conexion,'SELECT * FROM Faq');
while ($row = mysqli_fetch_array($res)) {
$rows[] = $row;
}
function filter(&$value) {
$value = htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
array_walk_recursive($rows, "filter");
return $rows;
mysqli_close($conexion);
return $rows;
}
和当我告诉它我得到:
我试图用 mysqli_set_charset($ conexion, “UTF-8”)
但它具有相同的输出...帮助=(
你试过在同一个页面上同时运行脚本,以确保该问题来自mysqli_而不是别的? –