Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP在回显时不剥离斜杠_Php - Fatal编程技术网

PHP在回显时不剥离斜杠

PHP在回显时不剥离斜杠,php,Php,我希望有人能帮我澄清这件事。我一直在读一本关于表单验证的最佳实践的书,如果用户输入了错误的值,请将表单返回给他们,并附上他们输入的数据和警告/错误消息 我想做的是,用户在文本框中输入以下内容: hello " there 我想在文本框中返回上面的内容。现在,当我使用下面的代码时,它添加了一个斜杠 <input name="name" id="name" type="text" class="formbox" <? php if ($missing || $

我希望有人能帮我澄清这件事。我一直在读一本关于表单验证的最佳实践的书,如果用户输入了错误的值,请将表单返回给他们,并附上他们输入的数据和警告/错误消息

我想做的是,用户在文本框中输入以下内容:

hello " there 
我想在文本框中返回上面的内容。现在,当我使用下面的代码时,它添加了一个斜杠

<input name="name" id="name" type="text" class="formbox"
    <?
        php if ($missing || $errors) {
            echo 'value="' . htmlentities($name) . '"';
        } 
    ?>
>

>
尽管上述方法有效,但似乎效率低下。如果我只使用'stripslashes',那么在'stripslashes'之后的任何内容都会被删除。当前表单只是在检查其自身,即当用户单击submit时,表单会重新加载,If语句会捕获任何帖子,然后检查是否有任何缺少的字段

我希望这一切都有意义,因为我一直无法在SO和Google上找到最佳解决方案


非常感谢您提前提供的帮助:)

您可以将它们结合起来以提高效率:

echo 'value="' . htmlentities(stripslashes($name)); . '"';

您可以使用函数$mysqli->real\u escape\u string($value)。它是mysqli类的一个函数。

我没有想到要做的是:

<?php 
    if ($missing || $errors) {
        echo 'value="' . stripslashes(htmlentities($name)) . '"';
    } 
?>>
>

这似乎是目前最好的方法。

最好的方法是关闭或升级PHP
<?php 
    if ($missing || $errors) {
        echo 'value="' . stripslashes(htmlentities($name)) . '"';
    } 
?>>