我先说几个:
1,假如你使用echo输出一个简单的语句,类似与:
复制代码 代码如下:
<?php
echo "hello world!";
?>
那么你可以偷懒一下,写成这样:
<?="hello world!";?>
echo "hello world!";
?>
那么你可以偷懒一下,写成这样:
<?="hello world!";?>
2,str_replace()可以使用数组进行替换,比如:
复制代码 代码如下:
<?
$string = "welcome to the phpchina.com ,have a good time.";
$search = array("welcome to the phpchina.com", "have a good time", ".");
$replace = array("php is very good", "i like it", "!");
$newstring = str_replace($search, $replace, $string);
echo $string."<br />";
echo $newstring;
?>
$string = "welcome to the phpchina.com ,have a good time.";
$search = array("welcome to the phpchina.com", "have a good time", ".");
$replace = array("php is very good", "i like it", "!");
$newstring = str_replace($search, $replace, $string);
echo $string."<br />";
echo $newstring;
?>
大家可不要把经验都藏起来哦,^_^!
多小的技巧算小技巧?
我记得以前发过这个缓存变量的函数 缓存目录为cache需要有读写权限 另外还有一个定时刷新用的函数先不写出来 否则就显得这个技巧太大了 其实和dz的刷新模式比较像
复制代码 代码如下:
function getquerycache($key){
$cacfile = "cache/" . $key . ".php";
if(file_exists($cacfile)){
@include($cacfile);
return $cacvalue;
}
return false;
}
function setquerycache($key, & $result){
$cacfile = "cache/" . $key . ".php";
$fp = fopen($cacfile, "w");
if(false != $fp){
fwrite($fp, "<?phpn$cacvalue = " . var_export($result, true) . "n?>");
fclose($fp);
return true;
}
return false;
}
$cacfile = "cache/" . $key . ".php";
if(file_exists($cacfile)){
@include($cacfile);
return $cacvalue;
}
return false;
}
function setquerycache($key, & $result){
$cacfile = "cache/" . $key . ".php";
$fp = fopen($cacfile, "w");
if(false != $fp){
fwrite($fp, "<?phpn$cacvalue = " . var_export($result, true) . "n?>");
fclose($fp);
return true;
}
return false;
}
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!