对输入值中的双引号进行转义

Ano*_*non 0 php

我有一个输入字段,其中 PHP 中回显的值使用 UTF-8 字符集进行编码

\n\n
<input value="<?php echo html_entity_decode($data["title"]); ?>" type="text">\n
Run Code Online (Sandbox Code Playgroud)\n\n

样本值:

\n\n
\n

“\xe0\xa4\xaa\xe0\xa5\x80\xe0\xa4\xb2\xe0\xa4\xbe\xe0\xa4\xb8\xe0\xa4\xbf\xe0\xa4\xa4\xe0\xa4\xbe\ xe0\xa4\xb0\xe0\xa4\xbe \xe0\xb0\xaa\xe0\xb0\xb8\xe0\xb1\x81\xe0\xb0\xaa\xe0\xb1\x81 \xe0\xb0\xa8\xe0\ xb0\x95\xe0\xb1\x8d\xe0\xb0\xb7\xe0\xb0\xa4\xe0\xb1\x8d\xe0\xb0\xb0\xe0\xb0\x82黄星!”

\n
\n\n

文本中出现的双引号导致该值无法显示。

\n\n

我已经尝试过这个,但它不起作用。

\n\n
<input name="title" id="title" value="<?php echo htmlspecialchars_decode(html_entity_decode($data["title"])); ?>"  class="width9" type="text"> type="text">\n
Run Code Online (Sandbox Code Playgroud)\n

TiM*_*TER 6

问题是你的方法不对。您尝试解码编码的字符串。但你必须对字符串进行编码。

所以你需要

htmlspecialchars($data["title"])
Run Code Online (Sandbox Code Playgroud)

并不是

htmlspecialchars_decode($data["title"])
Run Code Online (Sandbox Code Playgroud)

因为htmlspecialchars_decode()解码 htmlspecialchars 编码的字符串。