返回 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"="">

我尝试过添加斜杠($field_value),但它返回:

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

两个结果都不正确/有效。如何使输入值与 qoutes 正常工作。

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

使用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 或 http://www.w3schools.com/php/func_string_htmlentities.asp