最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php 简单生成html文件类
时间:2010-04-06 编辑:简简单单 来源:一聚教程网
class mkHtml{
var $url;
var $contents;
var $path;
function __construct() {
$this->url ='http://www.111com.net/';
$this->path ='../../default/';
}
function __destruct() {
unset( $this->url );
unset( $this->path );
unset( $this->contents );
}
function getHtml()
{
if(function_exists('file_get_contents') )
{
$this->contents =file_get_contents($this->url);
if( empty( $this->contents ) )
{
$this->curl();
}
}
else
{
$this->curl();
}
}
function curl()
{
$ch = curl_init();
$timeout = 10;
curl_setopt ($ch, CURLOPT_URL, $this->url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$this->contents = curl_exec($ch);
curl_close($ch);
}
function saveHtml()
{
$this->getHtml();
if( !empty( $this->contents ) )
{
if( ! is_dir( $this->path ) || ! is_writable( $this->path ) )
{
echo '目录不存或不可写!';
}
else
{
$handle = fopen($this->path.'default.html','w+');
fwrite($handle,$this->contents);
fclose($handle);
echo '生成首页成功';
}
}
else
{
echo '未开通文件远程读取函数,请在php.ini中去了extension=php_curl.dll前面";"或设置allow_url_fopen=On';
}
}
}
//使用方法
$html = new mkHtml();
$html->saveHtml();
//www.111cn.net教程原创,转载注明
-
上一个: ajax+php 无刷新数据调用经典实例
-
下一个: php中几种常见安全设置详解
相关文章
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24
- php数组查询元素位置方法介绍 10-24