1)扫描一个文件夹下的所有文件夹和文件:
<?php function scan($path){ static $arr=array(); //静态数组,用于存储扫描到的和文件夹 $filearr=scandir($path); foreach ($filearr as $value){ if($value==‘.‘ || $value==‘..‘){ continue; } if(is_file($path.‘/‘.$value)){ $arr[]=‘<font color=green>‘.$path.‘/‘.$value.‘</font>‘; } else { $arr[]=‘<font color=red>‘.$path.‘/‘.$value.‘</font>‘; scan($path.‘/‘.$value); } // if(is_dir($path.‘/‘.$value)){ // scan($path.‘/‘.$value); // } } return $arr; } $row=scan(‘../../‘); $count=count($row); echo ‘共查到‘.$count.‘个文件!<br/>‘; foreach ($row as $value) echo $value.‘<br/>‘;
2)删除非空文件夹:
<?php function del($path) { $res = @opendir ( $path ); if (! $res) { echo ‘文件或文件夹不存在,删除失败!‘; exit (); } while ( $file = readdir ( $res ) ) { if ($file != "." && $file != "..") { $fullpath = $path . "/" . $file; if (! is_dir ( $fullpath )) { unlink ( $fullpath ); } else { del ( $fullpath ); } } } closedir ( $res ); if (rmdir ( $path )) { return true; } else { return false; } } $path = "./a/"; if (del ( $path )) { echo "删除成功!"; } else { echo "删除失败!"; } ?>
3)Curl发送post请求:
<?php $data=array("appType"=>1,"IsJSON"=>1,"phone"=>18300000000); $url = "http://app.ron20.com:809/smspost.php?"; $res=doCurlPostRequest($url, $data, 10); var_dump($res); function doCurlPostRequest($url, $requestString, $timeout = 5) { if ($url == "" || $requestString == "" || $timeout <= 0) { return false; } $con = curl_init((string)$url); curl_setopt($con, CURLOPT_HEADER, false); curl_setopt($con, CURLOPT_POSTFIELDS, $requestString); curl_setopt($con, CURLOPT_POST, true); curl_setopt($con, CURLOPT_RETURNTRANSFER, true); curl_setopt($con, CURLOPT_TIMEOUT, (int)$timeout); curl_exec($con); }
4)php调用WEBSERVICE服务:
<?php class webSrvClass { //webservice 地址参数,调用webservice function soap($function, $par = array()) { //链接 web service 需要注意下面的url地址是.net提供的,后面加个?wsdl才是描述定义文件哈,请各自取正确的wsdl地址(每种web服务都有的) $client = new SoapClient("http://www.sz56it11.net:8088/Transjp.svc?wsdl", array(‘exceptions‘ => 0)); $require = $client->$function($par); //调用信息debug if (is_soap_fault($require)) { echo "远程接口" . $function . "调用失败!"; exit(); } //获取返回值 $function_result = $function . "Result"; $str = $require->$function_result; return $str; } //接口通讯记录 /*function soap_log($class, $function, $in, $out) { $log = date("Y-m-d H:i:s"); $log .= " " . $class . "->" . $function . " input:"; $input = ""; if ($in != array()) { foreach ($in as $key => $vlaue) { $input .= $key . "=" . $vlaue; } $log .= $input . " output:" . var_export($rows) . "\n"; } }*/ } //调用方法 $webserv = new webSrvClass; //这里是调用方法给传递的参数 $a = array("trackid" => "121211", "username" => "jpwl1", "password" => "jpwl888111"); echo ‘server echo:‘ . ($webserv->soap("querystatus", $a)); ?>
5)php获取页面完整url:
<?php function get_page_url(){ $url=(isset($_SERVER[‘SERVER_PORT‘])&&$_SERVER[‘SERVER_PORT‘]==‘443‘)? ‘https://‘:‘http://‘; $url.=$_SERVER[‘HTTP_HOST‘]; $url.=isset($_SERVER[‘REQUEST_URL‘])?$_SERVER[‘REQUEST_URL‘]:$_SERVER[‘PHP_SELF‘].‘?‘.$_SERVER[‘QUERY_STRING‘]; return $url; } ?>
6)php无限极分类:
//无限极函数 private function treelist($data, $cid, $deep = 1) { static $tree = array (); foreach ( $data as $row ) { if ($row [‘cid‘] == $cid) { $row [‘lever‘] = $deep; $tree [] = $row; $this->treelist ( $data, $row [‘id‘], $deep + 1 ); } } return $tree; } //取得数据 public function getList() { // 获取所有分类数据 $data = $this->fetchAll (); //list就是所有排序之后的数据 $list = $this->treeList ( $data, 0 ); return $list; } //在页面中展示 <div class="subnav"> {foreach from=$cdata item=‘value‘} {if $value[‘lever‘]==1} <div> <span class="left"> {$value[‘name‘]} </span> <span class="right subnav_right"> <img src="Public/Home/view/images/line.gif" border="0" id="categorie_ico3"></span> </div> {/if} <ul id="m3" style="display: block"> {if $value[‘lever‘]==2} <li> <a href="#"> {$value[‘name‘]} </a></li> {/if} </ul> {/foreach} </div>
时间: 2024-10-13 22:05:22