当前位置: 编程技术>php
本页文章导读:
▪php文件操作的小例子 代码如下:
<?php
ini_set('memory_limit', '-1'); //
ini_set("max_execution_time", "3600"); //设置超时时间
$filep='qq.txt';
$str=file('qq.txt');
$lineCount = 0;
foreach( $st.........
▪php json增加积分的函数举例 代码如下,仅供学习参考。
function zeng_integral(){
$jifen=& m('integral');
/*判断网吧*/
$store=isset()($store_id)?intval($store_id):0;
$injifen=$jifen->get(array('user_id'=>$_SESSION['user_info']['user.........
▪php遍历文件夹及其下所有文件的代码 代码如下:
<?php
/**
* 遍历文件夹下所有文件
* site www.
*/
$path = './filepath';
function getfiles($path)
{
if(!is_dir($path)) return;
$handle = opendir($path);
while( false !== ($file = re.........
[1]php文件操作的小例子
来源: 互联网 发布时间: 2013-12-24
代码如下:
<?php
ini_set('memory_limit', '-1'); //
ini_set("max_execution_time", "3600"); //设置超时时间
$filep='qq.txt';
$str=file('qq.txt');
$lineCount = 0;
foreach( $str AS $line ) {
$line = str_replace()( "\t", " ", $line );
$tr = trim( $line );
if ( preg_match( "/\\*|^\*|^ {1,}\*|\/\*|\*\/|^ {1,}\/\/|^\/\//", $line ) || $tr === "" ) {
continue;
}
$lineCount++;
$line = str_replace( "\r", "", $line );
$line = str_replace( "\n", "", $line );
if($lineCount<5){
is_m('5.txt',"".$line."@qq.com\n");
continue;
}elseif ($lineCount <10){
is_m('10.txt',"".$line."@qq.com\n");
break;
}
}
function is_m($filename,$c){
$handle = fopen($filename, "a");
if ($handle) {
fwrite($handle, $c );
fclose($handle);
}
}
?>
您可能感兴趣的文章:
php文件操作类的代码一例
一个不错的文本文件操作的php类
PHP文件操作方法问答
php中目录与文件操作详解
php目录与文件操作的实例教程
[2]php json增加积分的函数举例
来源: 互联网 发布时间: 2013-12-24
代码如下,仅供学习参考。
function zeng_integral(){
$jifen=& m('integral');
/*判断网吧*/
$store=isset()($store_id)?intval($store_id):0;
$injifen=$jifen->get(array('user_id'=>$_SESSION['user_info']['user_id']));
$yanzhen=json_decode()($injifen['integrallog'],true);
if(isset($injifen)){
$arrstore=array();
foreach ($yanzhen as $k=>$v){
$arrstore[]=$v['store_id'];
}
/*判断积分是否存在如果存*/
if (in_array($store,$arrstore)) {
foreach ($yanzhen as $key=>$val){
$yanzhen[$key]['store_id']=$key;
$yanzhen[$key]['jifen']=$val['jifen']+5;
}
$integral=json_encode($yanzhen);
}else {
foreach ($yanzhen as $key=>$val){
$yanzhen[$store]['store_id']=$store;
$yanzhen[$store]['jifen']=1;
}
$integral=json_encode($yanzhen);
}
/*构造数据*/
$data=array(
'integrallog'=>$integral,
);
$integ=$jifen->edit($injifen['id'],$data);
if ($integ) {
return true;
}
}else {
/*构造数组*/
$config=array();
$config[$store]['store_id']=$store;
$config[$store]['jifen']=1;
$integral=json_encode($config);
/*构造数据*/
$data=array(
'user_id'=>$_SESSION['user_info']['user_id'],
'integrallog'=>$integral,
);
$integ=$jifen->add($data);
if ($integ) {
return true;
}
}
}
[3]php遍历文件夹及其下所有文件的代码
来源: 互联网 发布时间: 2013-12-24
代码如下:
<?php
/**
* 遍历文件夹下所有文件
* site www.
*/
$path = './filepath';
function getfiles($path)
{
if(!is_dir($path)) return;
$handle = opendir($path);
while( false !== ($file = readdir($handle)))
{
if($file != '.' && $file!='..')
{
$path2= $path.'/'.$file;
if(is_dir($path2))
{
echo ' ';
echo $file;
getfiles($path2);
}else
{
echo ' ';
echo $file;
}
}
}
}
print_r( getfiles($path));
echo ' <HR>';
function getdir($path)
{
if(!is_dir($path)) return;
$handle = dir($path);
while($file=$handle->read())
{
if($file!='.' && $file!='..')
{
$path2 = $path.'/'.$file;
if(is_dir($path2))
{
echo $file."\t";
getdir($path2);
}else
{
echo $file.'';
}
}
}
}
getdir($path);
echo ' <HR>';
function get_dir_scandir($path){
$tree = array();
foreach(scandir($path) as $single){
if($single!='.' && $single!='..')
{
$path2 = $path.'/'.$single;
if(is_dir($path2))
{
echo $single." \r\n";
get_dir_scandir($path2);
}else
{
echo $single." \r\n";
}
}
}
}
get_dir_scandir($path);
echo ' <HR>';
function get_dir_glob(){
$tree = array();
foreach(glob('./curl/*') as $single){
echo $single." \r\n";
}
}
get_dir_glob();
echo ' <HR>';
function myscandir($path)
{
if(!is_dir($path)) return;
foreach(scandir($path) as $file)
{
if($file!='.' && $file!='..')
{
$path2= $path.'/'.$file;
if(is_dir($path2))
{
echo $file;
myscandir($path2);
}else
{
echo $file.' ';
}
}
}
}
myscandir($path);
echo ' <HR>';
function myglob($path)
{
$path_pattern = $path.'/*';
foreach(glob($path_pattern) as $file)
{
if(is_dir($file))
{
echo $file;
myscandir($file);
}else
{
echo $file.'
';
}
}
}
myglob($path);
?>最新技术文章: