0

I have 2 php pages. After submitting the form on page1 it's posted data is being displayed on page2. This works fine but some of characters like ' and " automatically get a \ just before themselves and the spaces are also gone.

For example I give ' " on page1. This is displayed as \' \" on page2. As you see the characters got \ attached and the spaces are also gone.

My code:

Page1.php

<html>
<head>
<title>PAGE 1</title>
</head>
<body>

    <form enctype="multipart/form-data" action="page2.php" method="post">
       <input type="text" name="txtNaam" id="txtNaam" />
       <input type="submit" value="Submit">
    </form>

</body>
</html>

Page2.php

<?php
// TEST 1
echo $_POST['txtNaam'];               // <== \' \"

echo "<br/>";   

// TEST 2
echo rawurlencode($_POST['txtNaam']); // <== %5C%27%20%20%20%20%5C%22

echo "<br/>";   

// TEST 3
echo urlencode($_POST['txtNaam']);    // <== %5C%27++++%5C%22
?>

How can I get these special characters correctly displayed when they are posted?

4

4 回答 4

1

尝试这个:

echo stripslashes($_POST['txtNaam']);
于 2013-08-13T14:11:54.593 回答
0

如果magic_quotes_gpc打开,PHP 中的所有$_GET,$_POST$_COOKIE变量 (GPC) 将已经有特殊字符,如",'\转义。

为防止这种情况发生,您可以禁用它。

像这样编辑你的php.ini

magic_quotes_gpc = Off
于 2013-08-13T13:56:19.963 回答
0

你也可以使用base64_encode () & base64_decode ()

于 2013-08-13T14:06:18.803 回答
0

你有没有尝试过

echo htmlspecialchars($_POST['txtNaam'], ENT_QUOTES);

或者

echo htmlentities(stripslashes($_POST['txtNaam']), ENT_QUOTES)
于 2013-08-13T13:59:35.887 回答