Answer the question
In order to leave comments, you need to log in
Why are HTML tags being output from JSON as is and not being rendered?
Good afternoon, how is the output from mysqli processed data with tags with html markup?
Is derived from the database:
And it is necessary that it be displayed
Development and support of sites
Data output comes from the database in JSON php
Разработка и поддержка <b>сайтов</b>
<?php
header('Content-Type: text/html; charset=utf-8');
header('Access-Control-Allow-Origin: *');
include 'DBConfig.php';
$link = mysqli_connect($HostName, $HostUser, $HostPass, $DatabaseName) or mysql_query("SET NAMES 'UTF-8'"); // Соединяемся с базой
// Ругаемся, если соединение установить не удалось
if (!$link) {
echo 'Не могу соединиться с БД. Код ошибки: ' . mysqli_connect_errno() . ', ошибка: ' . mysqli_connect_error();
exit;
}
//Само собой, КОДИРОВКА
mysqli_query($link, 'SET names UTF8');
//Сам запрос в базу MySQL
$sql = mysqli_query($link, "SELECT * FROM service WHERE id>0 ORDER BY status DESC, id DESC");
//МАССИВ JSON
$functions = [];
// Обход каждого элемента и добавление в Массив
while ($result = mysqli_fetch_array($sql)) {
$functions[] = $result = [
id => $result["id"],
name => $result["name"],
email => $result["email"],
thumbnailUrl => $result["thumbnailUrl"],
phone => $result["phone"],
category => $result["category"],
category_id => $result["category_id"],
parent_id => $result["parent_id"],
announce => $result["announce"],
status => $result["status"],
rating => $result["rating"],
visible => $result["visible"]
];
}
//Вывод jSON
$json = json_encode($functions, JSON_UNESCAPED_UNICODE);
echo htmlspecialchars_decode($json, ENT_HTML5);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question