HTML 태그가 포함 된 테이블에서 일부 데이터를 노출하려고합니다. 페이지에 액세스 할 때 HTML을 포함하지 않는 모든 필드는 괜찮지 만 HTML을 포함하는 모든 필드는 null을 반환합니다.html 태그를 포함 할 때 null을 반환하는 JSON 필드
필드를 VarChar 및 Text로 설정하려고했지만 어느 것도 작동하지 않는 것 같습니다. 표는 utf8_general_ci
으로 설정됩니다.
request_step_content.php
<?php
header("Content-Type:application/json");
header("Access-Control-Allow-Origin: *");
$user = "userName";
$pass = "userPassword";
$table = "myTable";
$db=new PDO("mysql:host=localhost;dbname=$table", $user, $pass);
$query = "SELECT * FROM steps";
try {
$stmt = $db->query($query);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error.";
die(json_encode($response));
}
$rows = $stmt->fetchAll();
if($rows) {
$response["success"] = 1;
$response["message"] = "Step";
$response["step"] = array();
foreach ($rows as $row) {
$post = array();
$post["id"] = $row["intID"];
$post["heading"] = $row["strStepheading"];
$post["keyPrinciple"] = $row["strKeyPrinciple"];
$post["pillar"] = $row["strPillar"];
$post["introduction"] = $row["memIntroduction"];
$post["actionSteps"] = $row["memActionSteps"];
$post["actionPoints"] = $row["memActionPoints"];
$post["studyAndUnderstanding"] = $row["memStudyUnderstanding"];
array_push($response["step"], $post);
}
echo json_encode($response);
}
else {
$response["success"] = 0;
$response["message"] = "No Steps Available";
die(json_encode($response));
}
?>
JSON 응답
{"success":1,
"message":
"Step",
"step":[{"id":"1",
"heading":"Test Heading",
"keyPrinciple":"Key Principle: Test Key Principle",
"pillar":"Pillar 1: Pillar",
"introduction":null,
"actionSteps":null,
"actionPoints":null,
"studyAndUnderstanding":null}]}
htmlentities 함수를 사용하여 HTML 행을 포함하는 $ row에 http://php.net/manual/fr/function.htmlentities.php를 작성하십시오. json_encode의 옵션을 사용하여 완료 할 수 있습니다. http://php.net/의 옵션 부분을 참조하십시오. manual/ko/function.json-encode.php – Fky
나는 HTML 엔티티를 구현했으며 필드를 null에서 empty로 변경했습니다. 나는 json_encode 옵션으로 무엇을 해야하는지에 대해 100 %가 아니다. – geolaw