程序员人生 网站导航

Parse Error: syntax error, unexpected $end 错误

栏目:php教程时间:2014-02-10 09:20:14

也许是不熟悉的php的一些特性吧,不过写多了,也就慢慢适应将就了,这里就整理一个代码编写调试问题,错误如下:Parse error: syntax error, unexpected $end in D:xampphtdocsguestBookguestBook.php on line 330

首先看看程序330行,代码最后一行,这有什么错误?google搜,找到了:

In PHP 5, the following error may appears as an error entry in Apache error log or simply displays on PHP web page, even if calling to php scripts with php_info() works perfectly and successfully returns information on PHP configurations:

Parse Error: syntax error, unexpected $end in ….. scripts.php on line …

The error may caused by a missing curly bracket in PHP script coding. Beside, it may also caused by error in PHP coding in class definition, as in PHP, a class definition cannot be broke up and distributed into multiple files, or into multiple PHP blocks, unless the break is within a method declaration.

But more commonly, the error is often caused by the use of Short Open tags in PHP,

To use short open tags, it must be enabled in PHP.INI. Search for short_open_tag in PHP.INI, and change the value to On. The line should look line:

short_open_tag = On

欺我英文不好啊?看看其它几条搜索,都没说到点子上,那就看看英文了,虽不能如数翻译,大致意思是瞧明白了:

错误发生是使用了短标签,可以在php.ini中设置short_open_tag = On

原来Parse error 提示一般是 语法错误,使用了开放的标签,语句没有结束 也就是编程基本的一些错, 比如没注意 语句结束加 ";" 或者 if(){...} 后面忘了"}" ;<?php...?>忘了"?>"。仔细检查代码,果然是一处漏掉了"}",修改程序正常运行,实例:

conn.php

  1. <?php 
  2. /* 
  3.  * PHP100Job v1.0 
  4.  * Programmer : Msn/QQ haowubai@hotmail.com (925939) 
  5.  * www.phpfensi.com Develop a project PHP - MySQL - Apache 
  6.  * Window 2003 - Preferences - PHPeclipse - PHP - Code Templates 
  7.  */ 
  8. $conn = @ mysql_connect("localhost""root""dong"or die("数据库链接错误"); 
  9. mysql_select_db("news"$conn); 
  10. mysql_query("set names 'GBK'"); //使用GBK中文编码; 
  11. function htmtocode($content) { 
  12. $content = str_replace("n""<br>"str_replace(" ""&nbsp;"$content)); 
  13. return $content
  14. //$content=str_replace("'","‘",$content); 
  15.  //htmlspecialchars(); 
  16.  
  17. ?> 
  18. <?php 
  19. /* 
  20.  * PHP100Job v1.0 
  21.  * Programmer : Msn/QQ haowubai@hotmail.com (925939) 
  22.  * www.php100.com Develop a project PHP - MySQL - Apache 
  23.  * Window 2003 - Preferences - PHPeclipse - PHP - Code Templates 
  24.  */ 
  25.  include("conn.php"); 
  26.  include("head.php"); 
  27.   $SQL="SELECT * FROM `message` order by id desc"
  28.   $query=mysql_query($SQL); 
  29.   while($row=mysql_fetch_array($query)){ 
  30. ?> 
  31. <table width=500 border="0" cellpadding="5" cellspacing="1" bgcolor="#add3ef"
  32.   <tr bgcolor="#eff3ff"
  33.   <td>标题:<?=$row[title]?> 用户:<?=$row[user]?></td> 
  34.   </tr> 
  35.   <tr bgColor="#ffffff"
  36.   <td>内容:<? 
  37.  echo htmtocode($row[content]); 
  38.   ?></td> 
  39.   </tr> 
  40. </table> 
  41. <? 
  42.   } 
  43. ?> 

运行出现下边的错误

Parse error: syntax error, unexpected $end in E:wampwwwleave_messagelist.php on line 35

报错的原因在这里<? } ?> 改成 <?php } ?>

解决办法:你把标题、内容,用户那三个改成<?php echo $row['title'];?>这样的就行了啊。函数就<?php echo htmtocode($row[content]); ?>,这不是主要的,至多只是显示不出.

------分隔线----------------------------
------分隔线----------------------------

最新技术推荐