《?php
echo __FILE__;
?>
E:phpinfo.php
那么我们会看到很多cms中会这样写
dirname(__FILE__);
这样会是什么结果呢,我们来试一下吧。
《?php
echo dirname(__FILE__);
?>
输出为 E:php
哈哈,明白了没其它的我就不说多了。
本站原创转载注明:www.111cn.net/phper/php.html
php isset() 与unset函数用法与区别很显了,isset是判断变量是否在存,而unset 是消除变量,下面我们来看看实现吧。php isset() 与unset函数用法与区别很显了,isset是判断变量是否在存,而unset 是消除变量,下面我们来看看实现吧。
<?php
$a = 1;
echo isset($a)?'中国WEB第一站':'www.111cn.net';
unset($a);
echo isset($a)?'中国WEB第一站':'www.111cn.net';
?>
输出结果为:
中国WEB第一站
www.111cn.net
我申明了$a所以会显示中国WEB第一站而后面的unset($a)就显示了www.111cn.net
好了简单啊,
本站原创文件转载注明:www.111cn.net/phper/php.html
在php中switch是选择,if else也有同理,但是它们肯定是有区别的,那么我们来看看它们两者的区别在哪里呢,下面先看switch case语句吧。
switch($id){
case 1:
return 'asp/';
break;
case 2:
return 'phper/';
break;
case 3:
return 'jsp/';
break;
default:
return 'rubbish/';
}
if else实现
if( $systype == 1 || $systype == 2 || $systype == 3 || $systype == 4 ){
return $sever;
}elseif ( $systype == 5 || $systype == 6 || $systype == 10
|| $systype == 11 || $systype == 12 || $systype == 9 || $systype ==7 ){
return $js;
}elseif ( $systype == 9 || $systype == 8 ){
return $sql;
}else{
return $system.$sever;
}
从上面的实例我们可以看出switch只能做一个选择,而if else 可以多个。
本站原创转载注明: www.111cn.net/php/phper.html
这是一款我自己没事时写的一款简单的把php文件生成html静态页面的程序代码哦,就是用str_replace来替换函数返回的数据就OK了。$fileName = md5_filename($rs[0],$rs['z_a'],$rs['filesendid']);
$path = get_path($rs['sysa']).$rs['z_a'].'/';
$parent = $_SERVER["DOCUMENT_ROOT"];//substr(getcwd(),0,strrpos(getcwd(),'\'));
$filePath = $parent.'\'.$path;
$tempLate = str_replace('{path}',path($rs['z_a'],$rs['sysa']),$fileContent);
$tempLate = str_replace('{htmlAbout}',htmlAbout($rs['z_a'],10,8,0,''),$tempLate);
$tempLate = str_replace('{htmlTemplate}',htmlTemplate(0),$tempLate);
$tempLate = str_replace('{htmlMenu}',htmlMenu($rs['sysa']),$tempLate);
$tempLate = str_replace('{htmlHelp}',htmlHelp($rs['sysa']),$tempLate);
$tempLate = str_replace('{htmlNews}',htmlAbout($rs['z_a'],0,8,0,''),$tempLate);
$tempLate = str_replace('{htmlHot}',htmlAbout($rs['z_a'],0,8,1,''),$tempLate);
$tempLate = str_replace('{htmlSoure}',htmlTemplate(1),$tempLate);
$tempLate = str_replace('php简单生成html静态页面代码',$rs['title'],$tempLate);
$tempLate = str_replace('{htmlContent}',$rs['content'],$tempLate);
$tempLate = str_replace('{description}',$rs['description'],$tempLate);
$tempLate = str_replace('{keywords}',$rs['keywords'],$tempLate);
makeHtml($tempLate,$filePath,$fileName);
function makeHtml($msgContent,$filePath,$fileName){//生成html文件
if(!is_dir($filePath)){@mkdir($filePath);}
//die($filePath);
$handle = fopen(str_replace('\','../',$filePath.$fileName),'w+') or die("can't create file!$fileName");
fwrite($handle,$msgContent);
fclose($handle);
}
本站原创转截注明:www.111cn.net/phper/php.html
下面这个函数是一个读取指定文件的内容然后再用php explode 与 implode来进行分析,然后我们再讲一下explode与implode的区别与使用方法 function htmlTemplate($tag){
$url ="file.txt";//file文件里面保存的是我要所数据并且是以<!-- 内容 -->为界线的。
$content = file_get_contents($url); 读取文件
if( !empty( $content ) ){
$array = explode('<!-- 内容 -->',$content); //进行数据处理,然后保存到数组array里面
}else{
echo 'error';
}
if( $tag ){
return $array[1];//数据1里面是保存了一段数据
}
$temp = $array[16];
$tempArray = explode('</span>',$temp); //16里面有数据</span>所以我们再进行inplode对数据进行合并成字符串就OK了。
for($i = 0 ;$i<=3;$i++) {
$tArray[] =$tempArray[$i];
}
return implode("</span>",$tArray ).'</span>';
}
本站原创转载注明:www.111cn.net/phper/php.html