class RecursiveFileFilterIterator extends FilterIterator
{
// 满足条件的扩展名
protected $ext = array('jpg','gif');
/**
* 提供 $path 并生成对应的目录迭代器
*/
public function __construct($path)
{
parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
}
/**
* 检查文件扩展名是否满足条件
*/
public function accept()
{
$item = $this->getInnerIterator();
if ($item->isFile() && in_array(pathinfo($item->getFilename(), PATHINFO_EXTENSION), $this->ext))
{
return TRUE;
}
}
}
// 实例化
foreach (new RecursiveFileFilterIterator('D:/history') as $item)
{
echo $item . PHP_EOL;
}
public class DirectoryContents
{
public static void main(String[] args) throws IOException
{
File f = new File("."); // current directory
FilenameFilter textFilter = new FilenameFilter()
{
public boolean accept(File dir, String name)
{
String lowercaseName = name.toLowerCase();
if (lowercaseName.endsWith(".txt"))
{
return true;
}
else
{
return false;
}
}
};
File[] files = f.listFiles(textFilter);
for (File file : files)
{
if (file.isDirectory())
{
System.out.print("directory:");
}
else
{
System.out.print(" file:");
}
System.out.println(file.getCanonicalPath());
}
}
}
$post_ =array (
'author' => 'Gonn',
'mail'=>'gonn@nowamagic.net',
'url'=>'http://www.nowamagic.net/',
'text'=>'欢迎访问简明现代魔法');
$data=http_build_query($post_);
$fp = fsockopen("nowamagic.net", 80, $errno, $errstr, 5);
$out="POST http://nowamagic.net/news/1/comment HTTP/1.1\r\n";
$out.="Host: typecho.org\r\n";
$out.="User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"."\r\n";
$out.="Content-type: application/x-www-form-urlencoded\r\n";
$out.="PHPSESSID=082b0cc33cc7e6df1f87502c456c3eb0\r\n";
$out.="Content-Length: " . strlen($data) . "\r\n";
$out.="Connection: close\r\n\r\n";
$out.=$data."\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp))
{
echo fgets($fp, 1280);
}
fclose($fp);
$opts = array (
'http'=>array(
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded\r\n" .
"Content-Length: " . strlen($data) . "\r\n",
'content' => $data)
);
$context = stream_context_create($opts);
file_get_contents('http://nowamagic.net/news/1/comment', false, $context);
$fp = fopen('c:/test.txt', 'w+');
/* 把rot13过滤器作用在写入流上 */
stream_filter_append($fp, "string.rot13", STREAM_FILTER_WRITE);
/* 写入的数据经过rot13过滤器的处理*/
fwrite($fp, "This is a test\n");
rewind($fp);
/* 读取写入的数据,独到的自然是被处理过的字符了 */
fpassthru($fp);
fclose($fp);
// output:Guvf vf n grfg
$streamlist = stream_get_filters(); print_r($streamlist);
Array ( [0] => convert.iconv.* [1] => mcrypt.* [2] => mdecrypt.* [3] => string.rot13 [4] => string.toupper [5] => string.tolower [6] => string.strip_tags [7] => convert.* [8] => consumed [9] => dechunk [10] => zlib.* [11] => bzip2.* )
class md5_filter extends php_user_filter
{
function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in))
{
$bucket->data = md5($bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
//数据处理成功,可供其它管道读取
return PSFS_PASS_ON;
}
}
stream_filter_register("string.md5", "md5_filter");
class md5_filter extends php_user_filter
{
public function filter($in, $out, &$consumed, $closing)
{
$data="";
while ($bucket = stream_bucket_make_writeable($in))
{
$bucket->data = md5($bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
call_user_func($this->params, $data);
return PSFS_PASS_ON;
}
}
$callback = function($data)
{
file_put_contents("c:\log.txt",date("Y-m-d H:i")."\r\n");
};
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有