【问题标题】:How to use variable inside parameter $_GET? example: ($_GET[$my_var])如何在参数 $_GET 中使用变量?示例:($_GET[$my_var])
【发布时间】:2013-10-01 21:19:13
【问题描述】:

我正在为 wordpress 开发一个插件,$_GET 的参数是根据用户通过 Wordpress 管理面板的偏好记录在数据库中的。以下验证必须通过 $ _GET,这是函数:

$db_url = get_option('my_get_url');
// returns the value of the database entered by User
// on this case return -->  page=nosupport

$url_explode = explode("=", $db_url);
$url_before = $url_explode[0]; // --> page
$url_after = $url_explode[1]; // --> nosupport

echo "Before: ".$url_before; // here are ok, return --> page
echo "After: ".$url_after; // here are ok, return --> nosupport

我的问题在这里:

// here $_GET no have any value, dont work on validate...
if($_GET[$url_before] != ""){ 
    if($_GET['$url_before']=="nosupport"){
        // my function goes here...
    }
}

我用于测试参数:

echo $_GET[$url_before];

但不返回任何值...

【问题讨论】:

  • $_GET['$url_before'] != $_GET[$url_before],去掉引号。
  • 除了引号的事情,他确实说未引用的版本仍然没有返回任何内容
  • 您可能需要检查整个$_GET 数组中的内容,以防$url_before 设置不正确..

标签: php wordpress variables parameters get


【解决方案1】:

我发现了问题,我已经测试了所有这些选项,但是从来没有工作过,问题是我正在我的网站主页内测试该功能,而在主页 (mysite.com) 上确实如此没有得到参数(?page=nossuport),所以总是返回空值​​,当我在GET中使用变量或使用echo $GET[$my_var]进行测试时..这是我的一个很大的粗心,会从不工作...

顺便说一下,这两个参数工作正常:

$_GET[$url_before]
$_GET["$url_before"]

问题已解决,谢谢帮助。

【讨论】:

    【解决方案2】:
    if($_GET[$url_before] != ""){ 
        if($_GET[$url_before]=="nosupport"){ // note no "" here
            // my function goes here...
        }
    }
    

    在您的解决方案中,密钥被视为字符串,没有评估任何变量。

    【讨论】:

      【解决方案3】:

      第二个条件你忘了去掉'。

      你写的:

           $_GET['$url_before']
      

      我猜应该是:

           $_GET[$url_before]
      

      【讨论】:

        【解决方案4】:

        foreach($_GET as $key => $value){ if($key == "不支持"){

        } }

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-07-21
          • 2013-05-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多