全球主机交流论坛

标题: 【已解决】关于在VPS写PHP的一些问题。技术帝请进! [打印本页]

作者: Mr.Ra1n    时间: 2012-8-3 11:33
标题: 【已解决】关于在VPS写PHP的一些问题。技术帝请进!
本帖最后由 Mr.Ra1n 于 2012-8-3 11:45 编辑

其实跟VPS没啥关系的。
你懂的。
  1. <?php
  2.         echo "testing";
  3.         @$step = $_GET['step'];
  4.         if ($step == 1 ){
  5.                 echo "this is step 1";
  6.         }
  7.         if ($step == 2 ){
  8.                 echo "this is step 2";
  9.         }
  10. ?>
复制代码
如果我想在请求 filename.php?step=1 的时候 不显示那个echo,怎么办?
也就是
默认显示A
step=1 的时候显示 B
step=2 的时候 显示C
  1. <?php
  2.         @$step = $_GET['step'];
  3.         if ($step == null ) {
  4.                 echo "testing";
  5.         }
  6.         if ($step == 1 ){
  7.                 echo "this is step 1";
  8.         }
  9.         if ($step == 2 ){
  10.                 echo "this is step 2";
  11.         }
  12. ?>
复制代码

作者: 360安全卫士    时间: 2012-8-3 11:35
本帖最后由 360安全卫士 于 2012-8-3 11:40 编辑

echo前加//
  1. <?php
  2.         echo "testing";
  3.         @$step = 1 ;
  4.         @$step = $_GET['step'];
  5.         if ($step == 1 ){
  6.                 echo "this is step 1";
  7.         }
  8.         if ($step == 2 ){
  9.                 echo "this is step 2";
  10.         }
  11. ?>
复制代码

作者: Mr.Ra1n    时间: 2012-8-3 11:37
360安全卫士 发表于 2012-8-3 11:35
echo前加//

访问filename.php的时候 还是要他显示的
作者: qqab    时间: 2012-8-3 11:38
啊 哦 这个有先后吧
作者: Mr.Ra1n    时间: 2012-8-3 11:39
qqab 发表于 2012-8-3 11:38
啊 哦 这个有先后吧

是的。。。
作者: nbclare    时间: 2012-8-3 11:39
else if ...
作者: 360安全卫士    时间: 2012-8-3 11:40
Mr.Ra1n 发表于 2012-8-3 11:37
访问filename.php的时候 还是要他显示的

已编辑
作者: Mr.Ra1n    时间: 2012-8-3 11:42
nbclare 发表于 2012-8-3 11:39
else if ...

重新看主题
作者: 454309099    时间: 2012-8-3 12:33
我不是很懂啊
作者: 过客    时间: 2012-8-3 12:55
默认是A,那你就判断$step是否为空即可。
作者: Kokgog    时间: 2012-8-3 13:17
点了提醒过来一看已解决.......
作者: nbclare    时间: 2012-8-3 22:11
用 @来抑制错误很不可取诶。。。
是不是可以这样。

$step = isset($_GET['step']) ? $_GET['step'] : 'default'

switch ($step) {
  case 1:
    ...
    break;
  case 2:
    ...
    break;
  ....
  default:
    ...
    break;
}
作者: qiqi13245    时间: 2012-8-3 22:12
- -。。。
if  xxx
   echo 啦啦啦啦;
   exit(); or return; or die;
作者: Mr.Ra1n    时间: 2012-8-4 21:06
nbclare 发表于 2012-8-3 22:11
用 @来抑制错误很不可取诶。。。
是不是可以这样。

哈哈~没想那么多。
作者: zt1993    时间: 2012-8-4 23:53
判断是否为空isset或者@!is_null或者@    empty()判断
作者: 34beat    时间: 2012-8-5 04:46
比較習慣:
<?
$id=$_GET[id];
if(!$id) $id=1;
if($id==1){}elseif($id==2){}
?>

總是覺得, 當! $id, 再設預設值比較好, 個人習慣




欢迎光临 全球主机交流论坛 (https://fd.vvwvv.eu.org/) Powered by Discuz! X3.4