首页 > 编程技术 > php

php isset() 与unset函数用法与区别

发布时间:2016-11-25 15:13

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正则表达式吧,下面来看看相关的函数php正则ereg ereg_replace eregi eregi_replace split等常用函数哦。

ereg()
ereg_replace()
eregi()
eregi_replace()
split()

(1)ereg,eregi
这是正规表达式匹配函数,前者是大小写有关匹配,后者则是无关的.
用法:
ereg(正规表达式,字符串,[匹配部分数组名]);
PHP3.0中的正规表达式大体类似于grep中用的.
(2)ereg_replace,eregi_replace
这些是替换函数.
用法:
ereg_replace(正规表达式,替换串,原字符串);
字符串处理函数中有一个strtr,是"翻译"函数,类似于Perl中的tr/.../.../,
用法:
strtr(字符串,"从","到");
例如:
strtr("aaabb","ab","cd")返回"cccdd".
(3)split
与explode函数有些类似,但这次可以在匹配某正规表达式的地方分割字符串.
用法:
split(正规表达式,字符串,[取出前多少项]);
 

__FILE__在php是表示当前文件绝对路径哦,下面我们来看看简单的FILE的实例吧。

《?php

echo __FILE__;

?>

E:phpinfo.php

那么我们会看到很多cms中会这样写

dirname(__FILE__);

这样会是什么结果呢,我们来试一下吧。

《?php

echo dirname(__FILE__);

?>

输出为 E:php

哈哈,明白了没其它的我就不说多了。

本站原创转载注明: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

标签:[!--infotagslink--]

您可能感兴趣的文章: