个字符...
Echo"$Short_Str";
Function csubstr($str,$start,$len)
{
$strlen=strlen($str);
$clen=0;
for($i=0;$i$strlen;$i++,$clen++)
{
if ($clen=$start+$len)
break;
if(ord(substr($str,$i,1))0xa0)
{
if ($clen=$start)
$tmpstr.=substr($str,$i,2);
$i++;
}
else
{
if ($clen=$start)
$tmpstr.=substr($str,$i,1);
}
}
return $tmpstr;
}
Function showShort($str,$len)
{
$tempstr = csubstr($str,0,$len);
if ($str$tempstr)
$tempstr .= "..."; //要以什么结尾,修改这里就可以.
return $tempstr;
}
6:规范你的SQL语句
在表格,字段前面加上"`",这样就不会因为误用关键字而出现错误,当然我并不推荐你使用关键字.
例如
$Sql="INSERT INTO `xltxlm` (`author`, `title`, `id`, `content`, `date`) VALUES ('xltxlm', 'use`', 1, 'criterion your
sql string ', '2003-07-11 00:00:00')"
"`"怎么输入? 在TAB键上面.
7:如何使Html/PHP格式的字符串不被解释,而是照原样显示
PHP代码:
?PHP
$str="h1PHP/h1";
Echo "被解释过的: ".$str."br经过处理的:";
Echohtmlentities(nl2br($str));
?
8:怎么在函数里取得函数外的变量值
PHP代码:
?PHP
$a="PHP";
foo();
Function foo()
{
global $a;//删除这里看看是什么结果
Echo "$a";
}
?
上一页[1][2][3][4][5]下一页
9:我怎么知道系统默认支持什么函数
PHP代码:
?php
$arr = get_defined_functions();
Function php() {
}
echo"pre";
Echo"这里显示
系统所支持的所有函数,和自定以函数php\n";
print_r($arr);
echo"/pre";
?
10:如何比较两个日期相差几天
PHP代码:
?PHP
$Date_1="2003-7-15";//也可以是:$Date_1="2003-7-15 23:29:14";
$Date_2="1982-10-1";
$d1=strtotime($Date_1);
$d2=strtotime($Date_2);
$Days=round(($d1-$d2)/3600/24);
Echo"偶已经奋斗了 $Days 天^_^";
?
11:为什么我升级PHP后,原来的
程序出现满屏的 Notice: Undefined variable:
这是警告的意思,由于变量未定义引起的.
打开php.ini,找到最下面的error_reporting,修改为error_reporting = E_ALL ~E_NOTICE
对于Parse error错误
error_reporting(0)无法关闭.
如果你想关闭任何错误提示,打开php.ini,找到display_errors,设置为display_errors = Off.以后任何错误都不会提示.
那什么是error_reporting?
12:我想在每个文件最前,最后面都加上一文件.但一个一个添加很麻烦
1:打开php.ini文件
设置 include_path= "c:"
2:写两个文件
auto_prepend_file.php 和 auto_append_file.php 保存在c盘,他们将自动依附在每个php文件的头部和尾部.
3:在php.ini中找到:
Automatically add files before or after any PHP document.
auto_prepend_file = auto_prepend_file.php;依附在头部
auto_append_file = auto_append_file.php;依附在尾部
以后你每个php文件就相当于
PHP代码:
?php
Include "auto_prepend_file.php" ;
.......//这里是你的程序
Include "auto_append_file.php";
?
13:如何利用PHP上传文件
PHP代码:
上一页[1][2][3][4][5]下一页
?
$upload_file=$_FILES['upload_file']['tmp_name'];
$upload_file_name=$_FILES['upload_file']['name'];
if($upload_file){
$file_size_max = 1000*1000;// 1M限制文件上传最大容量(bytes)
$store_dir = "d:/";// 上传文件的储存位置
$accept_overwrite = 1;//是否允许覆盖相同文件
// 检查文件大小
if ($upload_file_siz
e $file_size_max) {
echo "对不起,你的文件容量大于规定";
exit;
}
// 检查读写文件
if (file_exists($store_dir . $upload_file_name) !$accept_overwrite) {
Echo"存在相同文件名的文件";
exit;
}
//复制文件到指定目录
if (!move_uploaded_file($up