意外的T_ELSEIF [英] unexpected T_ELSEIF

查看:145
本文介绍了意外的T_ELSEIF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $ pages = array(grac,zamknij,dolaczyc); 
$ pagesid = array(showNews,showThread,showProfile);
$ b $ foreach($ pagesid as $ page){
if(isset($ _ GET [$ page])){
include('sobra /'.$ page。'。 PHP');


$ b //只是页面
elseif(in_array($ _ GET ['page'],$ pages)){
include( $ _GET [页码] .PHP);
}

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

给出:

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





谢谢 解决方案

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

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

 <?php 

//可接受页面的预定义列表
$ pages = array(one,two,three);
$ pagesid = array(four,five,six);

//收集任何用户定义的页面请求
$ desPage = trim($ _ GET [page]);

//假设他们错了,需要看到error.php
$ pageToLoad =error.php;

如果用户请求不为空
if(!empty($ desPage)){
if(in_array($ desPage,$ pages)){
$ pageToLoad = $ desPage。 .PHP;

} else {
//用户请求为空,检查其他变量
foreach($ pagesid as $ pageid){
if(isset($ _ GET [ $ pageid])){
$ pageToLoad = $ pageid。 .PHP;



$ b显示输出页面
include($ pageToLoad);

?>


$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');

gives:
Parse error: syntax error, unexpected T_ELSEIF in C:\WAMP\www\sdgag\index.php on line 33

This should work i think.. what the problem can be?

Thanks

解决方案

Perhaps another approach. Do your logic, and determine what page you want to include ultimately. After all of the logic has been done, include your determined page.

The following is untested, and may contain errors. Let me know, and I'll update the code.

<?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);

?>

这篇关于意外的T_ELSEIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆