写了一个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
请问这里哪里有语法错误,谢谢!(新手,请耐心回答,谢谢。)
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
楼上所言甚是。
你要把第一行分号后面的东西(隐藏字符)去掉。
另外要记得,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 { } ?>我复制了一下,你第一行后面多了点东西,你看看是不是多了什么不可见的字符。