Parse Error: syntax error, unexpected $end 錯誤_PHP教程

來源:互聯網
上載者:User
今天 在開發時碰到了關於Parse error: syntax error, unexpected $end 錯誤 提示,根據自己 的要驗這裡可能是 if else未成對出現,下面我們來總結一下問題和解決辦法。

也許是不熟悉的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(){...} 後面忘了"}" ;忘了"?>"。仔細檢查代碼,果然是一處漏掉了"}",修改程式正常運行

執行個體


conn.php

/*
* bkJiaJob v1.0
* Programmer : Msn/QQ haowubai@hotmail.com (925939)
* www.php100.com Develop a project PHP - MySQL - Apache
* Window 2003 - Preferences - PHPeclipse - PHP - Code Templates
*/

$conn = @ mysql_connect("localhost", "root", "dong") or die("資料庫連結錯誤");
mysql_select_db("news", $conn);
mysql_query("set names 'GBK'"); //使用GBK中文編碼;

function htmtocode($content) {
$content = str_replace("n", "
", str_replace(" ", " ", $content));
return $content;
}

//$content=str_replace("'","‘",$content);
//htmlspecialchars();

?>

/*
* bkJiaJob v1.0
* Programmer : Msn/QQ haowubai@hotmail.com (925939)
* www.php100.com Develop a project PHP - MySQL - Apache
* Window 2003 - Preferences - PHPeclipse - PHP - Code Templates
*/
include("conn.php");

include("head.php");
$SQL="SELECT * FROM `message` order by id desc";
$query=mysql_query($SQL);
while($row=mysql_fetch_array($query)){
?>








標題: 使用者:
內容: echo htmtocode($row[content]);
?>

}
?>
運行出現下邊的錯誤
Parse error: syntax error, unexpected $end in E:wampwwwleave_messagelist.php on line 35

報錯的原因在這裡
}
?>
改成
}
?>

解決 辦法

你把標題、內容,使用者那三個改成這樣的就行了啊。函數就

這不是主要的,至多隻是顯示不出資料
報錯的原因在這裡
}
?>
改成
}
?>

http://www.bkjia.com/PHPjc/632209.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632209.htmlTechArticle今天 在開發時碰到了關於Parse error: syntax error, unexpected $end 錯誤 提示,根據自己 的要驗這裡可能是 if else未成對出現,下面我們來總結一下...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.