作者:魔方16674 | 来源:互联网 | 2016-02-24 00:12
全系列PHP视频教程:细说PHP - http://www.xishuophp.com/
1、PHP翻转中文字符串
function reverse ( $str ) {$r = array ( ) ;for ( $i = 0 ; $i
2、PHP计算URL的文件后缀名
function getext ( $url ) {$data = parse_url ( $url ) ;$path = $data [ 'path' ] ;$info
= pathinfo ( $path ) ;return $info [ 'extension' ] ;}echo getext (
'http://blog.phpha.com/archives/1670.html?id=1670' ) ;//结果:'html'
3、PHP计算两个文件的相对路径
function getrpath ( $path , $conpath ) {$pathArr = explode ( '/' , $path ) ;
$cOnpathArr= explode ( '/' , $conpath ) ;$dismatchlen = 0 ;for ( $i = 0 ; $i
4、PHP遍历目录下的所有文件和文件夹
function finddir ( $dir ) {$files = array ( ) ;if ( is_dir ( $dir ) ) {if ( $handle =
opendir ( $dir ) ) {while ( ( $file = readdir ( $handle ) ) !== false ) {if ( $file != '.'
&& $file != '..' ) {if ( is_dir ( rtrim ( $dir , '/' ) . '/' . $file ) ) {$files [
$file ] = finddir ( rtrim ( $dir , '/' ) . '/' . $file ) ;} else {$files [ ] = rtrim ( $dir ,
'/' ) . '/' . $file ;}}}closedir ( $handle ) ;}}return $files ;}print_r ( finddir (
'F:/Golang/src' ) ) ;/**结果:Array([0] => F:/Golang/src/hello.go[1] =>
F:/Golang/src/src.exe[test] => Array([0] => F:/Golang/src/test/sss.txt))**/