我正在使用PHP,我希望在文本框中显示一个作为帖子标题的字符串作为值.如果此标题具有引号,则输入字段的字符串值标记将终止于该引号.现在因为有一个添加斜杠函数来添加反斜杠,是否有类似的函数来添加正斜杠?但就在引号之前,而不是任何其他角色
使用该htmlspecialchars函数对value="..."属性中的字符串进行编码.
例:
$sometext = 'Hello "world"!';
echo '<input type="text" value="' . htmlspecialchars($sometext) . '" />';
// outputs <input type="text" value="Hello "world"!" />
Run Code Online (Sandbox Code Playgroud)