本章可以算是上一章的延续,介绍了除文件实际内容之外的附加信息,包括文件的大小、目录、访问权限等。文件系统中的某些函数只在服务器为特定的系统中时才有效,例如更改符号链接的函数symlink(),设定文件访问权限的函数chmod(),设定目录访问权限的函数umask()等等这些只在Linux系统中有效,在Windows系统中无效。PHP5以后提供的DirectoryIterator类也封装了很多实用的目录方面的操作
php读出目录下的所有目录及子目录下文件
php正则字符串中图片地址表达式
结果显示:
php正则之从字符串中提取email地址
[PHP]代码
function extract_emails($str){
php读取文章中所有图片
php 获得用户的真实IP地址
js的escape转义中文php的转换函数
GB2312编码:
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/%u.{4}|&#x.{4};|&#d+;|.+/U",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u")
$ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,-4)));
elseif(substr($v,0,3) == "&#x")
$ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,3,-1)));
elseif(substr($v,0,2) == "&#") {
$ar[$k] = iconv("UCS-2","GBK",pack("n",substr($v,2,-1)));
}
}
return join("",$ar);
}
PHP货币换算程序代码
一款实用的PHP货币换算程序代码哦,有需要的朋友可以参考一下。
Copy the above code into a new file and save it as CurrencyConverter.php. Whenever you need to make a conversion just include the class file and call the ‘convert’ function. You will need to enter your own mysql database variables such as the login details. The example below will convert £2.50 GBP into US Dollars ($).
PHP 文件与目录删除程序
function RmDirFiles($indir)
{
$dh = dir($indir);
while($filename = $dh->read()) {
if($filename == "." || $filename == "..")
continue;
else if(is_file("$indir/$filename"))
@unlink("$indir/$filename");
else
$this->RmDirFiles("$indir/$filename");
}
$dh->close();
@rmdir($indir);
}
phpthink中字符串截取代码-支持中文和其它编码
php下载css中图片代码
<?php教程
$url = 'http://www.phprm.com';
$data = file_get_contents('abc.css教程');
preg_match('/(.*//.*?)//',$url,$host);
$host = $host[1];
if (!is_dir('img')) { mkdir('img'); }
$regex = '/url('http://pic2.phprm.com/2011/09/26/{0,1}"{0,1}(.jpg)/';
preg_match_all($regex,$data,$result);
foreach ($result[1] as $val) {
if (preg_match('/^http.*/',$val)) { $target = $val; }
else if (preg_match('/^/.*/',$val)) { $target=$host.$val; }
else { $target=$url.$val; }
echo $target."<br/>rn";
preg_match('/.*/(.*.D+)$/',$val,$name);
if (!is_file('./img/'.$name[1])) {
copy($target,'./img/'.$name[1]);
}
}?>
php 过滤字符串中链接地址
过滤链接最简单的办法就是利用php教程的strip_tags函数,如下
php过滤html的函数:strip_tags(string) 这样就可以过滤掉所有的html标签了。
如果想过滤掉除了<img src="">之外的所有html标签,则可以这样写:strip_tags(string,"<img>");
过滤除了<img src=""><p>xxx</p><b></b>之外的所有html标签,