$ _GET& “=” - 语法错误

时间:2013-10-24 07:21:08

标签: php get include

例如链接;

http://example.com/cast?Channel=STACKo

ChannelDatas.php;

 $STACKo_YAYIN = 'overflow';

的index.php;

  include '/***/Library/ChannelDatas.php';

  158 $_GET['Channel'] . '_YAYIN' = $insalik;
  159 $url = 'http://example.com/data/'.$insalik.'.info/weekly_'.$insalik.'.info_tvprofil.net.xml';

目标打印:

$url = 'http://example.com/data/overflow.info/weekly_overflow.info_tvprofil.net.xml'

错误页面:

 <b>Parse error</b>:  syntax error, unexpected '=' in <b>/***/v1/Index.php</b> on line <b>158</b><br />

怎么了?谢谢!

7 个答案:

答案 0 :(得分:1)

我认为你需要这样

$insalik = $_GET['Channel'] . '_YAYIN';

您正在$insalik使用$url。因此您需要将该值分配给$insalik。您已将其反转。

答案 1 :(得分:0)

您应该以这种方式引用$STACKo_YAYIN

$STACKo_YAYIN = 'overflow';
$insalik = ${$_GET['Channel'] . '_YAYIN'};
$url = 'http://example.com/data/'.$insalik.'.info/weekly_'.$insalik.'.info_tvprofil.net.xml';

答案 2 :(得分:0)

坏事从这里开始:

ChannelDatas.php;

$STACKo_YAYIN = 'overflow';

这应该是:

$YAYIN = array(
    "STACKo" => 'overflow',
);

然后访问很简单:

if (isset($YAYIN[$_GET['channel']]) {
    $url = 'http://example.com/data/'.$YAYIN[$_GET['channel']].'.info/weekly_'.$YAYIN[$_GET['channel']].'.info_tvprofil.net.xml';
} else {
    // what if there is no value for the channel?
}

答案 3 :(得分:-1)

使用以下

$_GET['Channel'] = '_YAYIN'.$insalik;

答案 4 :(得分:-1)

$_GET['Channel'] . '_YAYIN'是一个字符串。您不能将(=)值分配给字符串。 你需要反过来(将此字符串赋值给变量)

或者${$_GET['Channel'] . '_YAYIN'} = $insalik

答案 5 :(得分:-1)

您需要使用变量变量:

$insalik = ${$_GET['Channel'].'_YAYIN'};

http://php.net/manual/en/language.variables.variable.php

答案 6 :(得分:-1)

尝试参考变量

$temp = $_GET['Channel'] . '_YAYIN';
$insalik = $$temp;