apache服务器解决url中文无法正常显示解决办法
我们在php教程中用个url 编码函数,利用它就可以解决了,方法下如。
<?php
$interest = "arts";
$homepage = "http://www.111cn.net";
$query = "homepage=".urlencode( $homepage );
$query .= "&interest=".urlencode( $interest );
echo $query;
?>
设置php教程.ini 脚本超时方法
设置有二种
方法一,在php.ini里面设置
max_execution_time = 1800 ;
当前上面方法可以利用ini_set("选项","值"),
ini_set(''max_execution_time'', ''180'');
方法二 利用php页面中加
set_time_limit(),
如在php文档开始处加上set_time_limit(100),代表为100秒超时哦。
解决中文乱码解决方法有很多种,一种是对url编码如urlencode方法,另一种是下面的header头处理方法以binary方法。
<?php教程
$file_name = urlencode($_REQUEST['filename']);
header("Pragma: public"); header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header('Content-Type: application/vnd.ms-excel; charset=utf-8');
header("Content-Transfer-Encoding: binary");
header('Content-Disposition: attachment; filename='.$file_name);
echo strips教程lashes($_REQUEST['content']);
?>
php教程设置北京时间函数date_default_timezone_set()
定义和用法
date_default_timezone_set() 函数设置用在脚本中所有日期/时间函数的默认时区。
语法
date_default_timezone_set(timezone)
<?php
$now = time();
date_default_timezone_set('america/new york');
print date('c', $now);
date_default_timezone_set('europe/paris');
print date('c', $now);
?>
再看一个例子
<?php
date_default_timezone_set('america/denver');
$summer = mktime(12,0,0,7,4,2008);
print date('c', $summer) . "n";date_default_timezone_set('america/phoenix');
print date('c', $summer) . "n";
?>
注释:自 php 5.1.0 起(此版本日期时间函数被重写了),如果时区不合法则每个对日期时间函数的调用都会产生一条 e_notice 级别的错误信息,如果使用系统设定或 tz 环境变量则还会产生 e_strict 级别的信息。
参考表
表格 h-10. others
cet cst6cdt cuba eet egypt
eire est est5edt etc/gmt etc/gmt+0
etc/gmt+1 etc/gmt+10 etc/gmt+11 etc/gmt+12 etc/gmt+2
etc/gmt+3 etc/gmt+4 etc/gmt+5 etc/gmt+6 etc/gmt+7
etc/gmt+8 etc/gmt+9 etc/gmt-0 etc/gmt-1 etc/gmt-10
etc/gmt-11 etc/gmt-12 etc/gmt-13 etc/gmt-14 etc/gmt-2
etc/gmt-3 etc/gmt-4 etc/gmt-5 etc/gmt-6 etc/gmt-7
etc/gmt-8 etc/gmt-9 etc/gmt0 etc/greenwich etc/uct
etc/universal etc/utc etc/zulu factory gb
gb-eire gmt gmt+0 gmt-0 gmt0
greenwich hongkong hst iceland iran
israel jamaica japan kwajalein libya
met mst mst7mdt navajo nz
nz-chat poland portugal prc ps教程t8pdt
roc rok singapore turkey uct
universal utc w-su wet zulu
php教程支持gb2312,uft-8中英文字符截取函数
<?php
//截取gb2312中文字符串
function mysubstr($str, $start, $len) {
$tmps教程tr = "";
$strlen = $start + $len;
for($i = 0; $i < $strlen; $i++) {
if(ord(substr($str, $i, 1)) > 0xa0) {
$tmpstr .= substr($str, $i, 2);
$i++;
} else
$tmpstr .= substr($str, $i, 1);
}
return $tmpstr;
}
?>
<?php
//截取utf8字符串
function utf8substr($str, $from, $len)
{
return preg_replace('#^(?:[x00-x7f]|[xc0-xff][x80-xbf]+){0,'.$from.'}'.
'((?:[x00-x7f]|[xc0-xff][x80-xbf]+){0,'.$len.'}).*#s',
'$1',$str);
}
?>
把上面两个例子整合了
<?php
/*
utf-8、gb2312都支持的汉字截取函数
cut_str(字符串, 截取长度, 开始长度, 编码);
编码默认为 utf-8
开始长度默认为 0
*/
function cut_str($string, $sublen, $start = 0, $code = 'utf-8')
{
if($code == 'utf-8')
{
$pa = "/[x01-x7f]|[xc2-xdf][x80-xbf]|xe0[xa0-xbf][x80-xbf]|[xe1-xef][x80-xbf][x80-xbf]|xf0[x90-xbf][x80-xbf][x80-xbf]|[xf1-xf7][x80-xbf][x80-xbf][x80-xbf]/";
preg_match_all($pa, $string, $t_string);
if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen))."...";
return join('', array_slice($t_string[0], $start, $sublen));
}
else
{
$start = $start*2;
$sublen = $sublen*2;
$strlen = strlen($string);
$tmpstr = '';
for($i=0; $i< $strlen; $i++)
{
if($i>=$start && $i< ($start+$sublen))
{
if(ord(substr($string, $i, 1))>129)
{
$tmpstr.= substr($string, $i, 2);
}
else
{
$tmpstr.= substr($string, $i, 1);
}
}
if(ord(substr($string, $i, 1))>129) $i++;
}
if(strlen($tmpstr)< $strlen ) $tmpstr.= "...";
return $tmpstr;
}
}
$str = "abcd需要截取的字符串";
echo cut_str($str, 8, 0, 'gb2312');
?>