When you execute the created PHP code on the browser,
It is output with the contents described in html,

For example, I want, but it is output as<\/dt>.

I want to output correctly in,and html language.

I'm not sure where to modify the PHP code.
Or is it okay to pass it to Javascript as it is?

I have an additional question,
I think the html language encloses the class in double quotes "",
Is it safe to output with single quotation?

I've been studying PHP and MySQL since a week.
The purpose is to set the value of "Notification" on the homepage to the value obtained from DB.

Thanks for your cooperation.

"<Dl class = 'ns-news'><dt class = 'ns-date'>2020-07-11<\/dt><dd class = 'ns-text'>Hello.<\/Dd><\ /dl>"
$res = "";
$USER ='hoge';
$PW ='password';
$dnsinfo = "mysql:dbname=DBNAME;host=mysql1005b.xserver.jp;charset=utf8";
    $pdo = new PDO($dnsinfo, $USER, $PW);
    $sql = "SELECT * FROM information";
    $stmt = $pdo ->prepare($sql);
    $stmt ->execute(null);
    $res = "";
    while($row = $stmt ->fetch(PDO::FETCH_ASSOC)) (
    $res .= "<dl class='ns-news'><dt class='ns-date'>".$row['Date']."</dt><dd class='ns-text'>".$row['Textarea']."</dd></dl>";
header("Content-Type: text/javascript;charset=utf-8");
echo json_encode($res, JSON_UNESCAPED_UNICODE);
?>```Enter language here


  • Answer # 1

    For example, I want , but it is output as<\/dt>.

    There is no problem in particular. With a string in JSON\/Even if you enter/Since it has the same meaning as, there is no problem in using it.