PHP:双引号不显示在输入值中,但以正常回显显示
我在数据库中有一些字符串,例如 SNEAKERS SUPER STAR GOLDEN GOOSE
。这些是某些产品的标题。当我在< p>
内正常输出时,它会显示引号,但是当我在输入值内回显它时,< input type = text value =<?= $ product-&title; title?>
字符串在第一个双引号之前被截断,因此该值变为 SNEAKERS
。
I have some strings in the database like SNEAKERS "SUPER STAR" GOLDEN GOOSE
. These are the titles for some products. When I output it normally inside a <p>
it shows the quotes, but when I echo it inside an input value, <input type="text" value="<?= $product->title ?">
the string gets truncated before the first double quote, so the value becomes just SNEAKERS
.
有没有一种方法可以在输入值内输出双引号?
Is there a way I can output the double quotes inside the value of an input ?
编辑:
结束标记是一个错字,在代码中它是关闭的。
The closing tag was a typo, in the code it is closed.
使用 htmlspecialchars 像这样:
htmlspecialchars($product->title);
ie
<input type="text" value="<?= htmlspecialchars($product->title) ?>">