QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2736|回复: 12

PHP语法

[复制链接]
发表于 2006-1-2 08:28:11 | 显示全部楼层 |阅读模式
_POST[active]与_POST['active']含义有何不同?谢谢!
发表于 2006-1-4 10:16:39 | 显示全部楼层
$_POST本身是array,你可以print_r($_POST)看里面的数组的数据结构

你需要看看PHP的array相关的function
回复

使用道具 举报

发表于 2006-1-19 09:42:14 | 显示全部楼层
$POST[active]  是明白了,就是一个索引

但是$POST['active'] 不明白是什么意思



http://www.freesys.cn
没有恢复啊
打不开
回复

使用道具 举报

发表于 2006-1-19 10:06:59 | 显示全部楼层
比如URL的格式如下http://yourdoamin/index.php?action=login

$POST['active'] 得到的值就是login
回复

使用道具 举报

发表于 2006-1-19 10:07:49 | 显示全部楼层
服务器还不太稳定
回复

使用道具 举报

发表于 2006-1-19 11:11:03 | 显示全部楼层
index.php?id=1

我分别用了以下两种方式取id
$id = $_REQUEST['id'];
$id = $_POST['id'];

结果$_POST['id'] 取不到,只有$_REQUEST['id']能取到1
回复

使用道具 举报

发表于 2006-1-19 11:59:16 | 显示全部楼层
[code:1]
$id = isset($_POST['id']) ? $_POST['id'] : $_GET['id'];
[/code:1]
回复

使用道具 举报

发表于 2006-1-19 15:47:39 | 显示全部楼层
兔子,我的问题是

比如URL的格式如下http://yourdoamin/index.php?action=login
$_POST['action'] 是得不到 login  的。
$_REQUEST['action'] 才可以得到 login 的。

那么
_POST[action]与_POST['action']含义有何不同?
回复

使用道具 举报

发表于 2006-1-19 16:12:17 | 显示全部楼层
quicksand打破沙锅问到底 ^_^

看看PHP手册的相关信息:

An associative array of variables passed to the current script via the HTTP POST method. Automatically global in any scope.
将一个相关性的数组通过HTTP POST方法传递当前的脚本。在任意程序段内都属于全局变量。

那么$_POST[action]和$_POST['action']都表示$_POST数组里key值为action对应的值

在看看Array的相关概念:

[code:1]
array( [key =>] value
     , ...
     )
// key may be an integer or string
// value may be any value  是的,key值可以使整型或字符串
[/code:1]

Why is $foo[bar] wrong?为什么它错了呢?
You should always use quotes around a string literal array index. For example, use $foo['bar'] and not $foo[bar]. But why is $foo[bar] wrong? You might have seen the following syntax in old scripts:
通常都会在数组索引处加上"" 。比如,使用$foo['bar']而不是$foo[bar]。但是为什么$foo[bar]错了呢?你可能在老代码中看到过:

[code:1]
<?php
$foo[bar] = 'enemy';
echo $foo[bar];
// etc
?>  
[/code:1]

This is wrong, but it works. Then, why is it wrong? The reason is that this code has an undefined constant (bar) rather than a string ('bar' - notice the quotes), and PHP may in future define constants which, unfortunately for your code, have the same name. It works because PHP automatically converts a bare string (an unquoted string which does not correspond to any known symbol) into a string which contains the bare string. For instance, if there is no defined constant named bar, then PHP will substitute in the string 'bar' and use that.
这是错的,但是它能显示些东东。那么,为什么它错了?因为这个代码是一个未定义的常量(bar)而不是一个字符串('bar'注意那个''),而PHP将来会定义一些常量,而不幸的是在你的代码中使用了同样的名称。后面的不用翻译了...

看看PHP手册的相关内容

[code:1]
$variable = isset($_POST['variable']) ? $_POST['variable'] : $_GET['variable'];
[/code:1]
同样也是标准的获得URL中参数的办法
回复

使用道具 举报

发表于 2006-1-19 19:16:35 | 显示全部楼层
总算明白啦,呵呵,      
谢谢 热情的兔子~~

正好我这几天也在接触php,所以也同样有好奇,活活~~
回复

使用道具 举报

发表于 2006-1-19 19:21:13 | 显示全部楼层
看到你的网站了,很Cool
回复

使用道具 举报

发表于 2006-1-19 23:05:09 | 显示全部楼层
POST、GET 是不同的数据传送,具体区分我不太清楚,我只知道 <form> </form>这个标签可以设置以 POST 还是 GET 方式发送。
似乎 REQUEST 应该同时包含了 POST  GET 以及另一个全程变量的数据。
回复

使用道具 举报

发表于 2006-1-20 09:56:35 | 显示全部楼层
Request variables: $_REQUEST

An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE由$_GET, $_POST, $_COOKIE相关内容组成的数组
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-25 12:54 , Processed in 0.076996 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表