5
У меня есть PHP, который выводит json.Вывести HTML в строку JSON, сгенерированную PHP
<?php
$html = utf8_encode($gegevens['tekst']);
$html = htmlentities($html);
//$html = htmlspecialchars($gegevens['tekst'], ENT_QUOTES, 'UTF-8');
echo json_encode(array('titel' => $gegevens['titel'], 'html' => $html));
?>
Выход будет как:
{"titel":"Here comes the title","html":"<strong>Here is the HTML<\/strong>\n<br \/>\n<br \/>\n And some more."}
а также JQuery/Ajax будет:
$.ajax({
type: "GET",
url: "content/popup.php?id=" + id2,
dataType: 'json',
crossDomain: true,
success: function(json) {
var titel = json['titel'];
var html = json['html'];
function ContentTonen()
{
// Div's legen van content
$('.popup_home_head_inside').empty();
$('.popup_home_content_inside').empty();
$('.popup_home_head_inside').html(titel);
var html2 = html.replace(/\"/g, "");
//$('.popup_home_content_inside').html(html2);
$('.popup_home_content_inside').html(html2);
И выход HTML является:
<strong>Some HTML</strong> <br /> Some more text.
Так это не будет обрабатываться как HTML.
Можете ли вы мне помочь?
Как подготовить HTML для JSON тогда? Стриптиз не работает. – Daan
Какой препарат вы имеете в виду? – Jithesh
Когда я вставляю HTML непосредственно в JsonEncode, он возвращает null. Потому что это недействительно JSON. С htmlentities JsonEncode принял строку как действительную JSON. Но какую функцию я должен использовать, чтобы подготовить HTML к действию JSON? – Daan