A small PHP document generation class.
In the project development of the discovery of the PHP document lack of management, others wrote a, not much function
/** * Class Name: Doc * Description: Document Generation class * Other: You can filter the directory, set the source directory, use absolute path to specify the build directory, mode is adjustable, mode * 1 is the general type, that is, the slash * * starts with a * slash end * 2 for the extension type, general slash * Start with * The end of the slash will be part of the document */class Doc {var $docdirname; var $docdir; /** * Function name: Doc () * Function function: Construct * input parameter: none * function return Value: Return value Description * Other Description: 2004-10-13 */function doc () {$this->docdirn Ame = "doc/"; }/** * Function name: Createdoc ($root, $newdir, $mode = "1", $filter =null) * Function function: Create document * input parameter: $root--------------source Directory $newdir- ----------target directory $mode-------------mode, 1 is normal, 2 is extended $filter------------Filter directory * Function return value: Description of Return value * Other Description: 2004-10-13 */func tion Createdoc ($root, $newdir, $mode = "1", $filter =null) {$getarr = $this->loopdir ($root, $filter); $i = 0; $this->createframe ($newdir); foreach ($getarr as $key = + $val) {if ($this->getphpfiles ($val)) {$content = $this->getcontent ($val); $content = $this->getdoc ($content, $mode); $filepath = $this->setfilepath ($val, $root, $newdir); $filedir = $this->getfiledir ($filepath); $this->mkdirs ($fileDIR); $this->setdoc ($filepath, $content); $data [$i] [' url '] = "$filepath"; $data [$i] [' name '] = "$val"; $i + +; }} if (!empty ($data)) {$this->createmenu ($newdir, $data); $this->redirect ($this->docdir); }}/** * Function name: Redirect ($path) * Function function: Steering * input parameter: $path----------------Steering Path * Function return value: Description of Return value * Other Description: 2004-10-13 * /function Redirect ($path) {echo "}/** * Function name: Loopdir ($root, $filter =null) * Function function: Traverse directory * input parameter: $root---------- ---------Source Directory $filter-----------------filter * function return value: Array * Other instructions: 2004-10-13 */function Loopdir ($root, $filter =null) {static $getarr =array (); $d = Dir ($root); while (false!== ($entry = $d->read ())) {if ($entry = = "." | | $entry = = "..") {continue; if ($this->filter ($entry, $filter)) {if (Is_dir ($root. $entry)) {$this->loopdir ($d->path. $entry. /"); } else {$getarr [] = $d->path. $entry; }}} $d->close (); Return $getarr; }/** * Function name: getphpfiles ($path) * Function function: Extract PHP document * Input parameters: $pAth----------------Document PATH * function return value: BOOL * Other Description: 2004-10-13 */function Getphpfiles ($path) {$type = Preg_replace ('/. *\. (.*[^\.]. *)/I ', ' \\1 ', $path); $type = Strtolower ($type); if ($type = = "php") {Return true; } else {Return false; }}/** * Function name: getcontent ($path) * Function function: Read file contents * Input parameters: $path-------------------File path * function return value: String * Other instructions: 200 4-10-13 */function GetContent ($path) {$fp = file ($path); $content = Implode (' ', $fp); Return $content; }/** * Function name: Getdoc ($content, $mode = "1") * Function function: Remove comments in PHP file * Input parameters: $content------------document Content $mode--------------- mode, 1 is normal, 2 is extended * function return value: String * Other Description: 2004-10-13 */function Getdoc ($content, $mode = "1") {switch ($mode) {case ' 1 ' : $pattern = '/\/(\*) [\r\n].*\*\//isu '; Break Case ' 2 ': $pattern = '/\/\*.*\*\//isu '; Break } preg_match_all ($pattern, $content, $carr); $getarr = Array (); foreach ($carr [0] as $key = + $val) {$getarr [] = Trim ($val); } $STR = Implode ("
", $getarr); $str = preg_replace ('/[\r]/i ', '
', $STR); $style = $this->getstyle (); $str = $this->gettable ($STR); $str = $style. $str; Return $str; }/** * Function name: Etfilepath ($filepath, $oldroot, $newroot) * Function function: Set the path of the generated file * Input parameters: $filepath--------------source file path $oldro OT--------------Source directory path $newroot--------------destination directory path * function return value: String * Other Description: 2004-10-13 */function SetFilePath ($fi Lepath, $oldroot, $newroot) {$oldroot = Str_replace ('/', "\\/", $oldroot); $pattern = "/". $oldroot. " (. *)/iu "; $filepath = Preg_replace ($pattern, ' \\1 ', $filepath); $newpath = $newroot. $this->docdirname. $filepath;//echo "$newpath
"; $newpath = Preg_replace ('/(. *\.) (.*[^\.]. *)/I ', ' \\1htm ', $newpath); Return $newpath; }/** * Function name: Getfiledir ($path) * Function function: Get document Directory * Input parameters: $path-------------Document PATH * function return value: String * Other Description: 2004-10-13 */function Getfiledir ($path) {$getpath = Preg_replace ('/(. *) (\/.*[^\.]. *)/I ', ' \\1 ', $path); Return $getpath; }/** * Function name: Setdoc * Function function: Write note to the specified directory and generate page * Input parameters: $filepath---------------directory path $content----------------written content * function return Value: Description of Return value * Other Description: Description */function Setdoc ($filepath, $content) {$fp = fopen ($filepath, "w+"); Flock ($FP, LOCK_EX); Fwrite ($fp, $content); Flock ($FP, lock_un); }/** * Function name: mkdirs ($path) * Function function: Create directory * input parameter: $path-------------------path * function return value: None * Other Description: 2004-10-13 */ function Mkdirs ($path) {$adir = explode ('/', $path); $dirlist = "; $rootdir = $adir [0]; Array_shift ($adir); foreach ($adir as $key = + $val) {if ($val! = '. ') && $val! = ' ... ') {$dirlist. = "/". $val; $dirpath = $rootdir. $dirlist; if (!file_exists ($dIrpath) &&!is_file ($dirpath)) {mkdir ($dirpath); chmod ($dirpath, 0777); }}}}/** * Function name: Filter ($item, $arr =null) * Function function: Filter * input parameter: $item--------------content $arr---------------Filter Item * function return Value: BOOL * Other Description: 2004-10-13 */function filter ($item, $arr =null) {$item = Strtolower ($item); $filter = Explode (', ', $arr); if ($arr ==null| |! In_array ($item, $filter)) {Return true; } else {Return false; }}/** * Function name: createframe ($root) * Function function: Generate frames page * Input parameters: $root---------------Home directory * function return value: STR * Other instructions: 2004-10 -13 */function Createframe ($root) {$str = '
<title>Untitled Document</title>
<noframes>&lt;body&gt; &lt;/body&gt;</noframes>
'; $this->docdir = $root. " Index.htm "; $this->setdoc ($this->docdir, $STR); }/** * Function name: CreateMenu ($root, $data) * Function function: Generate menu * Input parameters: $root-------------------page into the directory $data------------------- Content * Function return value: String * Other Description: 2004-10-13 */function CreateMenu ($root, $data) {$path = $root. " Menu.htm "; $str = $this->getstyle (); $str. = "
"; foreach ($data as $key = = $val) {$str. = "
| } $str. = " |
"; $this->setdoc ($path, $STR); }/** * Function name: GetStyle () * Function function: Style * input parameter: none * function return Value: String * Other Description: 2004-10-13 */function GetStyle () {$st R = ''; Return $str; }/** * Function name: getTable ($content) * Function function: put content into table * input parameter: $content------------content * Function return value: String * Other instructions: 2004-1 0-13 */function getTable ($content) {$str = "
"; Return $str; }}//Use $d = new doc; $filter = "Adodb,smarty,cvs,templates,templates_c"; $d->createdoc ("e:/www/kpub20/class/", "e:/www/test/aaa/", 1, $filter);