Rumah > Soal Jawab > teks badan
写了一个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
请问这里哪里有语法错误,谢谢!(新手,请耐心回答,谢谢。)
欧阳克2016-11-19 14:24:35
楼上所言甚是。
你要把第一行分号后面的东西(隐藏字符)去掉。
另外要记得,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 { } ?>