php - 有关 if 条件句错误
本文介绍了php - 有关 if 条件句错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
写了一个kirby CMS的API,发现不停报错。
先上代码:
<?php if(!defined('KIRBY')) die('Direct access is not allowed');
if (isset($_GET['get']) || isset($_GET['transshipment']))
{
if (isset($_GET['get']) && !isset($_GET['transshipment']))
{
if ($_GET['get'] == 'title')
{
if (null !== $page->title())
{
echo "E303";//no title setted
die();
}
echo $page->text()->title();
die();
}
elseif ($_GET['get'] == 'content')
{
if (null !== $page->content())
{
echo "E303";//no content setted
die();
}
echo html($site->title()->content());
die();
}
elseif ($_GET['get'] == 'author')
{
if (null !== $page->author())
{
echo "E303";//no author setted
die();
}
echo $page->author();
die();
}
elseif ($_GET['get'] == 'dates')
{
if (null !== $page->dates())
{
echo "E303";//no dates setted
die();
}
echo $page->dates();
die();
}
elseif ($_GET['get'] == 'introduction')
{
if (null !== $page->introduction())
{
echo "E303";//no introduction setted
die();
}
echo $page->introduction();
die();
}
else
{
echo "E301";//error API information getting(error after "=")
die();
}
}
elseif (!isset($_GET['get']) && isset($_GET['transshipment']))
{
echo "E302";//error API information getting(error before "=")
die();
}
elseif (isset($_GET['get']) && isset($_GET['transshipment']))
{
echo "E304";//error API information getting(getting value override)
die();
}
else
{
}
}
else
{
}
?>
保存后在尝试打开时发现报错:
[18-Nov-2016 12:02:14 UTC] PHP Parse error: syntax error, unexpected 'if' (T_IF) in /home/sunhbjaq/public_html/site/templates/work.php on line 2
请问这里哪里有语法错误,谢谢!
(新手,请耐心回答,谢谢。)
解决方案
楼上所言甚是。
你要把第一行分号后面的东西(隐藏字符)去掉。
另外要记得,PHP说 第X行出现错误 的时候,一定要从 X-1 行开始找错。
<?php if(!defined('KIRBY')) die('Direct access is not allowed');
if (isset($_GET['get']) || isset($_GET['transshipment']))
{
if (isset($_GET['get']) && !isset($_GET['transshipment']))
{
if ($_GET['get'] == 'title')
{
if (null !== $page->title())
{
echo "E303";//no title setted
die();
}
echo $page->text()->title();
die();
}
elseif ($_GET['get'] == 'content')
{
if (null !== $page->content())
{
echo "E303";//no content setted
die();
}
echo html($site->title()->content());
die();
}
elseif ($_GET['get'] == 'author')
{
if (null !== $page->author())
{
echo "E303";//no author setted
die();
}
echo $page->author();
die();
}
elseif ($_GET['get'] == 'dates')
{
if (null !== $page->dates())
{
echo "E303";//no dates setted
die();
}
echo $page->dates();
die();
}
elseif ($_GET['get'] == 'introduction')
{
if (null !== $page->introduction())
{
echo "E303";//no introduction setted
die();
}
echo $page->introduction();
die();
}
else
{
echo "E301";//error API information getting(error after "=")
die();
}
}
elseif (!isset($_GET['get']) && isset($_GET['transshipment']))
{
echo "E302";//error API information getting(error before "=")
die();
}
elseif (isset($_GET['get']) && isset($_GET['transshipment']))
{
echo "E304";//error API information getting(getting value override)
die();
}
else
{
}
}
else
{
}
?>
这篇关于php - 有关 if 条件句错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文