意外的T

$pages = array("grac", "zamknij", "dolaczyc");
$pagesid = array("showNews", "showThread", "showProfile");

foreach ($pagesid as $page) {
  if (isset($_GET[$page])) {
  include('sobra/'.$page.'.php');
  }
}

// just pages
elseif (in_array($_GET['page'], $pages)) {
include("$_GET[page].php");
}

// error
else include('error.php');

得到:
第33行的C: WAMP www sdgag index.php中解析错误:语法错误,意外的T_ELSEIF

这应该工作,我想..问题可以是什么?

谢谢


也许另一种方法。 做你的逻辑,并确定你最终要包含哪个页面。 完成所有逻辑后,请包含您确定的页面。

以下内容未经测试,可能包含错误。 让我知道,我会更新代码。

<?php

  // Predefined list of acceptable pages
  $pages = array("one","two","three");
  $pagesid = array("four","five","six");

  // Gather any user-defined page request
  $desPage = trim($_GET["page"]);

  // Assume they are wrong, and need to see error.php
  $pageToLoad = "error.php";

  // If the user request is not empty
  if (!empty($desPage)) {
    if (in_array($desPage,$pages)) {
      $pageToLoad = $desPage . ".php";
    }
  } else {
  // User request is empty, check other variables
    foreach ($pagesid as $pageid) {
      if (isset($_GET[$pageid])) {
        $pageToLoad = $pageid . ".php";
      }
    }
  }

  // Show output page
  include($pageToLoad);

?>

elseif和else不附加到if,你把它们放在foreach循环块之外。


在其他情况之前,还有一个左括号。

它应该是:

$pages = array("grac", "zamknij", "dolaczyc");
$pagesid = array("showNews", "showThread", "showProfile");

foreach ($pagesid as $page) {
  if (isset($_GET[$page])) {
    include('sobra/'.$page.'.php');
  }
  // just pages
  else if (in_array($_GET['page'], $pages)) {
    include("$_GET[page].php");
  }
  // error
  else include('error.php');
}   

如果你正确缩进你的源代码,这样的错误显示很快,你可以自己修复它们。

链接地址: http://www.djcxy.com/p/12025.html

上一篇: unexpected T

下一篇: ELSE and I don't know why