Php 双引号和输入的问题

Php 双引号和输入的问题,php,html,Php,Html,我有以下代码: <input type="text" value="<?php echo $_GET['msg']; ?>"> 您应该使用函数来转义HTML的输出: <input type="text" value="<?php echo htmlspecialchars($_GET['msg']); ?>"> 您应该使用函数来转义HTML的输出: <input type="text" value="<?php echo html

我有以下代码:

 <input type="text" value="<?php echo $_GET['msg']; ?>">

您应该使用函数来转义HTML的输出:

<input type="text" value="<?php echo htmlspecialchars($_GET['msg']); ?>">

您应该使用函数来转义HTML的输出:

<input type="text" value="<?php echo htmlspecialchars($_GET['msg']); ?>">
/是这方面的标准方式。你应该用它

在通过电子邮件发送实体之前,您始终可以对其进行解码,或者使用进行其他处理。

/是实现此目的的标准方法。你应该用它


在通过电子邮件发送实体之前,您始终可以对实体进行解码,或者使用它们执行其他操作。

一种或另一种功能会导致一些麻烦

我想出了以下方法来保留符号:

<input type="text" value="<?php echo parseString($_GET['msg']); ?>">
<?php
function parseString($str) {
    $result=str_replace('"','&quot;',$str);
    $result=str_replace("'","&#39;",$result);
    return $result;
} 

一种或另一种功能会导致某种故障

我想出了以下方法来保留符号:

<input type="text" value="<?php echo parseString($_GET['msg']); ?>">
<?php
function parseString($str) {
    $result=str_replace('"','&quot;',$str);
    $result=str_replace("'","&#39;",$result);
    return $result;
} 

我很好奇为什么您创建了这个函数,而不是使用内置的
htmlspecialchars
,正如前面(正确)的答案所指出的。我很好奇为什么您创建了这个函数,而不是使用内置的
htmlspecialchars
,正如前面(正确)的答案所指出的。