Home > Backend Development > PHP Tutorial > PHP collects books and synthesizes the implementation code in txt format_PHP tutorial

PHP collects books and synthesizes the implementation code in txt format_PHP tutorial

WBOY
Release: 2016-07-21 15:48:13
Original
1171 people have browsed it

/**
* @name collection book.php
* @date Sun Mar 01 22:48:02 CST 2009
* @copyright Ma Yongzhan (MyZ)
* @author Ma Yongzhan (MyZ)
* @link http://blog.csdn.net/mayongzhan/
*/
//header('Content-Type:text/html;charset=utf8');
header('Content-Type:text/html;charset=gb2312');
error_reporting(E_ALL);
date_default_timezone_set('Asia/Shanghai');
set_time_limit(0);
function writer($content,$url)
{
$fp = fopen($url, 'ab');
fwrite($fp, $content);
fclose($fp);
}
$folder = '2'; //文件夹
$book_base_url = 'xxxxxxxxxxxxxxxxxxxxx';
$book_url = 'yyyyyyyyyyyyy.html';
$main = file_get_contents($book_base_url.$book_url);
preg_match_all('/chapter_.*?.html/', $main, $pages);
$pages = array_unique($pages[0]);
foreach ($pages as $value) {
writer(file_get_contents($book_base_url.$value), './'.$folder.'/'.$value.'.txt');
$str = file_get_contents('./'.$folder.'/'.$value.'.txt');
//print_r($str);
preg_match("/(

)(.*?)(

)(.*?)(
)(.*?)(
)/s",$str,$arr);
//print_r($arr);die();
$arr[6] = preg_replace("/(]+>.*?]+>)(.*?)()/s","$2",preg_replace("/

|

/","rn",$arr[6]));
$result = "rn------------------------------------------------rn------------------------------------------------rn------------------------------------------------rn----------------".$arr[2]."rn------------------------------------------------rn------------------------------------------------rn------------------------------------------------rn".$arr[6];
writer($result, './'.$folder.'/new.txt');
}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/319775.htmlTechArticle?php /*** @name collection book.php * @date Sun Mar 01 22:48:02 CST 2009 * @copyright Ma Yongzhan (MyZ) * @author Ma Yongzhan (MyZ) * @link http://blog.csdn.net/mayongzhan/*/ //header('Conten...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template