为什么post一个form的string在另一页面变了?

我的中有'字符,但是form中的数据到另一个页面用$_POST读出来后所有的'都变成了'

!!!????

为什么?
---------------------------------------------------------------

等了好一会没人回答,所以找了一下,呵呵,
应是这样了,
PHP 和 HTML 有很多相互作用:PHP 能生成 HTML,HTML 可以向 PHP 传递信息。
1. 当我通过表单/URL 传值时需要用什么编码/解码方法?
2. 我在试用

1<input type="image"/>

标记,但是没有 $foo.x 和 $foo.y 变量,它们哪去了?
3. 怎样在 HTML 的

1<form> 中建立数组?   
24\. 怎样从可多选的 HTML 的 select multiple 标记中得到所有结果?   
31\. 当我通过表单/URL 传值时需要用什么编码/解码方法?   
4在几个环节上编码方式很重要。假定你有 string $data,其中包含了你想通过非编码方式传递的字符串,那这是相关步骤:   
5HTML 解析。要指定一个任意的字符串,你必须将其放在双引号中,并用 htmlspecialchars 处理整个值。   
6URL:URL 由几部分组成。如果你希望自己的数据被当作其中一项来解释,你必须用 urlencode() 对其编码。   
7例子 51-1. 隐藏的 HTML 表单单元   

echo "<input ""="" .="" htmlspecialchars($data)="" type="hidden" value='""'/>\n";

1注: 用 urlencode() 来处理 $data 是错误的,因为是浏览器的责任来 urlencode() 数据。所有流行的浏览器都能正确处理。注意不论何种方法(例如 GET 或 POST)都会这样。不过你只会在用 GET 请求时注意到这一点,因为 POST 请求通常是隐藏的。   
2例子 51-2. 等待用户编辑的数据   

echo "<textarea name="mydata">\n";
echo htmlspecialchars($data)."\n";
echo "</textarea>";

 1注: 数据会按照预期的显示在浏览器中,因为浏览器会解释 HTML 转义符号。   
 2当提交时,不论是 GET 或者 POST 方法,数据都会被浏览器进行 urlencode 来传输,并直接被 PHP urldecode。所以最终你不需要自己处理任何 urlencoding/urldecoding,全都是自动处理的。   
 3  
 4\---------------------------------------------------------------   
 5  
 6有些站点禁止post内容包含',因为这通常跟一些脚本语言、sql的有冲突,所以往往做些过滤   
 7\---------------------------------------------------------------   
 8  
 9这是因为magic_quotes_runtime 开关被打开了,系统自动加上的。   
10可用get_magic_quotes_runtime函数检查,set_magic_quotes_runtime函数设置   
11\---------------------------------------------------------------   
12  
13addslashes   
14(PHP 3, PHP 4 )   
15  
16addslashes -- Quote string with slashes   
17Description   
18string addslashes ( string str)   
19  
20Returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote ('), double quote ("), backslash (\\) and NUL (the NULL byte).   
21  
22注: magic_quotes_gpc is ON by default.   
23  
24stripslashes   
25(PHP 3, PHP 4 )   
26  
27stripslashes -- Un-quote string quoted with addslashes()   
28Description   
29string stripslashes ( string str)   
30  
31Returns a string with backslashes stripped off. (\' becomes ' and so on.) Double backslashes are made into a single backslash   
32\-----------------------------------------------   
33用stripslashes函数处理一下就好了, 不需要去改php.ini的设置.</form>
Published At
Categories with Web编程
comments powered by Disqus