访问php程序时,报如下的错误:
Parse error: syntax error, unexpected $end in D:\xampp\htdocs\guestBook\guestBook.php on line 330
看看程序 330行,代码最后一行,这有什么错误?找到了:
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...?>忘了"?>"。仔细检查代码,果然是一处漏掉了"}",修改程序正常运行。
通常在Windows下,使用csv导入数据时,使用GBK在Windows的Excel中编辑。
不过在服务器端,多是linux系统了,源程序使用UTF-8,此时很容易产生字符编码的问题。
如果仅仅将CSV文件转码为UTF-8,在Windows服务器上没有问题;
而在RedHat5.5上,用fgetcsv取得的数组中,如果某列的内容是中文,则该列对应的数组元素为空字符串,而英文则正常。
此时需要设置区域:
setlocale(LC_ALL, 'zh_CN.UTF-8');
在php程序中可以这样操作:
<?php
// 上传的CSV文件,通常是用Excel编辑的GBK编码,
// 而源代码是UTF-8,需要进行转码处理
file_put_contents($new_file, iconv('GBK', 'UTF-8', file_get_contents($new_file)));
//ini_set('auto_detect_line_endings', true);
// 设置区域:简体中文,UTF-8编码
setlocale(LC_ALL, 'zh_CN.UTF-8');
// 打开CSV文件
$handle = fopen($new_file, 'r');
// 取出列头
$data_heads = fgetcsv($handle);
?>
一个php的防盗链代码,供朋友们学习参考吧。
<?php
/**
* @author seraphim
* @copyright 2013
* url: http:www.
*/
$ADMIN = array(
'defaulturl'=> 'http://www.xx.com/images/banner-header.gif', //盗链返回的地址
'url_1' => 'http://www.xx.net/file',
'url_2' => 'http://www.xx.net/file1',
);
$okaysites = array(
'http://box.baidu.com',
'http://tieba.baidu.com/p/1493336008', //白名单
'http://www.xx.com/1.html',
);
$reffer = $_SERVER['HTTP_REFERER'];
if ($reffer) {
$yes = 0;
while (list($domain, $subarray) = each($okaysites)) {
if (ereg($subarray, "$reffer")) {
$yes = 1;
}
}
$theu = 'url_' . $_GET['site'];
$file = $_GET['file'];
if ($ADMIN[$theu] and $yes == 1) {
header("Location: $ADMIN[$theu]/$file");
} else {
header("Location: $ADMIN[defaulturl]");
}
} else {
header("Location: $ADMIN[defaulturl]");
}
print_r($_SERVER['HTTP_REFERER']);
/*
url: http://www.
*/
?>