php 目录和文件操作
<?php
//新建目录
mkdir("/path/to/my/dir", 0700); //0700表示权限最大
//删除目录
rmdir("/path/to/my/dir");
//遍历目录
$p =dir(/etc/php5);
echo "handler:".$p->handler;
while(false!=$entry=$p->read()){
echo $entry."\n" ;
}
$p->close();
//输出文件内容
$handle=@fopen("/tmp/file.txt","r"); //fopen也可以打开一个url
if($handle){
while(!feof($handler)){
echo fgets($handler,4096);
}
}
//二进制形式打开
$filename="/tmp/file.txt";
$handle=@fopen($filename,"b");?>
if($handler){
$content=fread($handler,filesize($filename));
fclose($handler);
echo $content;
}
//获得url内容
$html=file_get_contents(http://www.baidu.com);
echo $html;
相关文档:
<?
/**
* xml2array() will convert the given XML text to an array in the XML structure.
* Link: http://www.bin-co.com/php/scripts/xml2array/
* Arguments : $contents - The XML text
* $get_attributes - 1 or 0. If this is 1 the function will get the attributes as well as the ......
本文介绍的脚本易于理解、使用简单并可以快速掌握。
简单的掷骰器
许多游戏和游戏系统都需要骰子。让我们先从简单的部分入手:掷一个六面骰子。实际上,滚动一个六面骰子就是从 1 到 6 之间选择一个随机数字。在 PHP 中,这十分简单:echo rand(1,6);。
在许多情况下,这基本上很简单。但是在处理机率游戏时,我们需要 ......
php中如何关闭notice级的错误提示
2008-09-04 15:39
1.在php.ini文件中改动error_reporting
改为:
error_reporting = E_ALL & ~E_NOTICE
如果你不能操作php.ini文件,你可以用下面的方法 ......
我们的电话报名系统中,呼叫中心收集了用户的银行信息,然后请求银行的支付接口的webservice,需要进行超时设置,因为不能一直让学员等待
解决方法是
1:首先先要看一下php.ini里的默认超时时间,一般是120秒
2:在php代码里加上
ini_set('default_socket_timeout', 10);//设置超时时间
如下图
......
1. PHP的COOKIE
cookie 是一种在远程浏览器端储存数据并以此来跟踪和识别用户的机制。
PHP在http协议的头信息里发送cookie, 因此 setcookie() 函数必须在其它信息被输出到浏览器前调用,这和对 header() 函数的限制类似。
1.1 设置cookie:
可以 ......