0

我正在尝试在包含的文件中包含一个文件我想要包含它的点是在 switch 语句中。出于某种原因,它不起作用,它让我发疯。据我所知,在包含中包含或在大括号中放置包含是没有障碍的。我得到的具体错误是

Parse error: syntax error, unexpected T_INCLUDE, expecting T_CASE or T_DEFAULT or '}' i 

任何人都可以发现错误吗?对此有一些禁止吗?

第一个文件。

<?php include("includes/getdata.php"); ?> 

第一个包含的文件

<?php
//some code
switch ($action)
{
?>
<?php include("words.php"); ?>
<?php
}
//rest of code
?>

包含在包含(words.php)中

<?php
case 'research':
$word = "web";
break;
//various other cases

?>
4

3 回答 3

1

Just read the error message again.

switch (...) {
    include ...
}

This is invalid. You need a case or default keyword before any other code in a switch statement:

switch (...) {
    case ... :
        include ...
}

What you're trying to do doesn't work and is a bad idea to begin with.

于 2012-11-30T10:52:57.607 回答
0

wrong syntax of switch case

switch(expression)
{
  case 'some value' : //you code; break;
  default: // default code
}

so you must need to add default: include_once 'word.php'

于 2012-11-30T10:52:08.313 回答
0

Why are you consistently opening and closing PHP blocks?

//some code
switch ($action) {
    include("words.php");
}
//rest of code

This is wrong because you've not stated a case for the action.

//some code
switch ($action) {
    case 'A': // This is mandatory
      include("words.php");
      break;
}
//rest of code
于 2012-11-30T10:52:42.510 回答