快讯

PHP入门速成(2)

2004-02-14 09:33  出处:PConline  作者:飞鹰/ASPCool.com  责任编辑:zwg 

  B. 处理表单 我们通过页面的第二个功能模块完成对表单输入结果的处理过程。其代码如下: < ?php function process_form() { global $name; global $fruit; global $times;   if ($fruit == ‘apple’) { $fruit_message = ‘You love apple.’; } elseif ($fruit == ‘orange’) { $fruit_message = ‘You love orange’; } else { $fruit_message = ‘You love banana.’; }   $favorite_times = count($times);   if ($favorite_times < = 1) {$times_message = ‘You should eat fruit more often.’;} elseif ($favorite_times > 1 && $favorite_times < 4) {$times_message = ‘Those are good times to eat fruit.’;} else {$times_message = ‘You are eating too much fruit.’;}   echo “Hello $name.”; echo “$fruit_message $times_message”; } ? >   在表单处理代码中,首先我们按照上文所介绍的$PHP_SELF变量处理方式,将我们在创建表单时所建立的变量全部声明为全局变量。接着,我们查看用户具体选择了哪一个fruit选项。然后,使用count()函数得出用户选择的复选选项的个数,然后按照该结果进行相应的判断。最后,我们输出用户的姓名以及表单处理后的信息。
键盘也能翻页,试试“← →”键
IT热词搜索 来源:360新闻
软件论坛帖子排行
相关文章

相关软件:

腾讯QQ2012
大小:52.93 MB 授权:免费
腾讯QQ2012
立即下载
腾讯QQ2013
大小:49.32 MB 授权:免费
腾讯QQ2013
立即下载