PHP语法解释

PHP语法解释,php,string,syntax,Php,String,Syntax,我如何翻译成PHP语法,比如: if(isset($_GET['q'])//but q=is not empty or <2 because in this case redirect to) { do this } else { do this one } 你喜欢这样吗 <?php if(isset($_GET['q'])) { if(!empty($_GET['q']) || $_GET['q']<2) { header("location

我如何翻译成PHP语法,比如:

if(isset($_GET['q'])//but q=is not empty or <2 because in this case redirect to) { do this } else { do this one }
你喜欢这样吗

<?php
if(isset($_GET['q']))
{
    if(!empty($_GET['q']) || $_GET['q']<2)
    {
        header("location:somepage.php");
    }
    else
    {
        echo "Cannot be redirected";
    }
}
你喜欢这样吗

<?php
if(isset($_GET['q']))
{
    if(!empty($_GET['q']) || $_GET['q']<2)
    {
        header("location:somepage.php");
    }
    else
    {
        echo "Cannot be redirected";
    }
}

什么?你是说你的文字代码吗

if(isset($_GET['q']) && (!empty($_GET['q']) || $_GET['q'] < 2)) {
  // redirect here using header("location: foo.php") or some other function if you are using some framework.
}
else {
  /otherwise do something else.
}
更新您的更新问题:


因为$u GET['q']不是空的?做一个$u的var_转储,这样我们和你都知道里面有什么。不可能有别的说法。但我认为你的代码正是按照你告诉它的去做的。你只是不知道你想要完成什么。

什么?你是说你的文字代码吗

if(isset($_GET['q']) && (!empty($_GET['q']) || $_GET['q'] < 2)) {
  // redirect here using header("location: foo.php") or some other function if you are using some framework.
}
else {
  /otherwise do something else.
}
更新您的更新问题:

因为$u GET['q']不是空的?做一个$u的var_转储,这样我们和你都知道里面有什么。不可能有别的说法。但我认为你的代码正是按照你告诉它的去做的。你只是没有你想要完成的事情的全貌。

我假设q是一个数字

if (isset($_GET['q']) {
    if (empty($_GET['q'] || $_GET['q'] < 2)) {
        // do redirect here
    } else {
        // do mysql here
    }
}
我假设q是一个数字

if (isset($_GET['q']) {
    if (empty($_GET['q'] || $_GET['q'] < 2)) {
        // do redirect here
    } else {
        // do mysql here
    }
}

你的URL查询字符串看起来怎么样?@ShankarDamodaran href=./page.php?q=如果你的URL像page.php,那么@ShankarDamodaran href=./page.php之间有一个空格。q=如果你的URL像page.php,你的代码会重定向。q=这意味着没有为qURL查询字符串传递值。你的URL查询字符串看起来怎么样?@ShankarDamodaran href=./page.php?q=在@ShankarDamodaran href=./page.php之间有一个空格如果您的URL类似于page.php?q=这意味着没有为qq传递值,那么您的代码将重定向。如果您的URL类似于page.php?q=这意味着没有为q传递值……因为代码逻辑就是这样编写的。如果您希望逻辑以另一种方式运行,请更改!在第一条if语句中为空。如果URL类似于page.php?q=则代码重定向,这意味着没有为q传递值……因为代码逻辑就是这样编写的。如果您希望逻辑以另一种方式运行,请更改!在第一个if语句中为空。