return 带有 qoute 值的输入字段不起作用

return input field with qoute values not working

我有一个创建输入字段的函数。

$string = '<input type="' . $field_type . '" class="form-control" id="' . $field_name . '" name="' . $field_name . '" value="' . $field_value . '">';
return $string

$field_value 保存一个带有 qoutes 的字符串。
var_dump $field_value 的结果:

string(19) ""Open Sans",Verdana"

当我查看 Chrome 的开发人员工具中的源代码时,结果是:

 <input type="text" class="form-control" id="themesettings[main_body_font_family]" name="themesettings[main_body_font_family]" value="" open="" sans",verdana"="">

我试过 addslashes($field_value) 但是 returns:

<input type="text" class="form-control" id="themesettings[main_body_font_family]" name="themesettings[main_body_font_family]" value="\" open="" sans\",verdana"="">

两个结果都不是correct/working。如何使输入值与 qoutes 一起正常工作。

使用htmlentities($field_value)它会将"转换为html个实体

<?php 
 $field_value_converted = htmlentities($field_value);
?>

<input ... value="<?php echo $field_value_converted ?>" >

在此处查看有关 htmlentities() 功能的更多信息:http://php.net/manual/en/function.htmlentities.php OR http://www.w3schools.com/php/func_string_htmlentities.asp

您试图做的是掩盖引号。 HTML 中的屏蔽不是通过添加 \ 或其他东西来完成的,而是通过用所谓的 HTML 实体替换它来完成的。因此,您必须用 &quot; 替换所有引号。您可以使用 PHP 本机函数 htmlentities().

轻松完成此操作