gpt4 book ai didi

php - 使用 PHP 生成 HTML 时处理撇号

转载 作者:行者123 更新时间:2023-11-28 05:06:25 24 4
gpt4 key购买 nike

我正在根据 XML 配置值生成单选按钮。有时他们在文本中有撇号。在 PHP 中处理这些数据时,我似乎在撇号后丢失了所有内容。例如:

<input type='radio' name='remove[]' value='Government wants to limit employers' communications about unionization'>

但是在表单 POST 之后将其转储出来时,我得到了这个值:

array(1) {
[0]=>
string(35) "Government wants to limit employers"
}

关于如何保留完整字符串有什么建议吗?谢谢!

最佳答案

使用 htmlspecialchars() :

<input type="radio" ... value="<?php echo htmlspecialchars($array[0], ENT_QUOTES) ?>" ... />

它的明确目的是允许在不“破坏” html 的情况下将任意文本安全地插入到 html 中。注意“ent_quotes”选项。默认情况下 htmlspecialchars 只会处理 <>" , 但由于您使用的是 ' ,您还需要告诉 htmlspecialchars 处理这些选项。

关于php - 使用 PHP 生成 HTML 时处理撇号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7030611/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com