Main topic: Many PHP websites in the detailed page of the PHP website are all html, how did you do it? Author: Gaosj (I really want to make a programmer) level: credit value: 100 community: Web development PHP problem points: 100 Reply times: 10 Posted: 2005-03-12 09:05:41
How did some PHP sites go in a click when it is html? I know like http://aaaha.com/aa.php?id=12, but how can you convert it to http://aaa.com/2005-03-08.htm? Thank you, you can tell!
Reply to: keaizhong (cute bell) () Reputation: 103 2005-03-12 09:29:00 Score: 0
Generate a static page.
TOP
Reply to: MyNamesucks (Seasons In the Sun) Reputation: 100 2005-03-12 09:46:00 Score: 0
http://www.7880.com/info/Article-369f2780.html
TOP
Reply to: wapweb (big cabbage core) () reputation: 72 2005-03-12 11:24:00 Score: 0
The generation of static pages generally has such a few ideas. .
1. The program is written during the program. Do not use the direct output statement. When all outputs are connected to the output string, after the output is complete. Write the output string directly to the file
2. Written in normal ways. Capture the output by the OB function group. Then write the output to the file
3. When using a template class, the output is obtained with the method of GET / FETCH. And write to the file.
Specific implementation has both methods
1. When you add a record, you can generate the target HTML page directly, and the front call connection directly points to the generated HTML page. This method is the highest in program efficiency. The server load is light, but since the generated pure static page, once the page style has changed, all content pages must be regenerated. So the application in actual use is generally not too much. More is the use of clients such as JS, SSI, XML / XSL, and only save data in the generated static file, does not involve styles, so that speed and maintenance balance can be achieved, but it is complex relative to the front and backbound procedures (application) When this method, since the content is pure static, it can be used with pure static Apache, which is compiled .. efficiency and resource occupation more better than including dynamic content support
2. The front access link points to the PHP program, and the PHP program first checks if there is a corresponding static file. If the static file does not exist. Then generate and redirect to this file, otherwise redirect directly. This method is actually used in conjunction with the URL_rewrite functionality in Apache. Will be in the form of HTML of the PHP file address, which is conducive to the search engine search. This method is slightly losses in efficiency, but the program structure is simple, easy to adjust, and use is suitable when the amount of access is not very large.
E.g:
step one:
Read this news, output to the static page generated by Smarty's Fetch () to the specified place, the general file name specifies the time or file name of the HTML file, and then writes this name, such as a database.
Step 2:
When the content is displayed again, it is judged that if you html's name, then the HTML name is displayed. Specific code segment, wait for me to show you :)
TOP
Reply to: edlongren (edlongren) () Reputation: 99 2005-03-12 11:35:00 Score: 0
The principle is to read it, write into a static page ~~
TOP
Reply to: Hahawen (metamorphosis of old age) () reputation: 133 2005-03-12 14:42:00 Score: 0
Using Apache's Web re-direction, it is to use his REWRITE module to configure Apache simple implementation. Specific views can take a look at the Apache manual TOP
Reply to: Hahawen (metamorphosis of old age) () reputation: 133 2005-03-12 14:45:00 Score: 0
Or he is a dynamically generated static page
TOP
Reply to: JulyChina (Nine Codes) () Reputation: 95 2005-03-12 15:57:00 Score: 0
Class HTML
{
Var $ dir; // File storage directory, directory name (without /)
Var $ rootdir; // html file stored root directory, directory name (without /)
Var $ name; // html file storage path
Var $ dirname; // Specified folder name
Var $ URL; // Get the source web address of the HTML file information
VAR $ TIME; / / HTML file information is fill in time
Var $ dirty; // directory storage
Var $ nametype; // html file naming method
Function HTML ($ NameType = 'Name', $ dirtype = 'Year', $ rootdir = 'html')
{
$ this-> setvar ($ NameType, $ DIRTYPE, $ ROOTDIR);
}
Function setvar ($ NameType = 'Name', $ dirtype = 'Year', $ rootdir = 'html')
{
$ this-> rootdir = $ rootdir;
$ this-> dirtype = $ dirtype;
$ this-> nametype = $ nametype;
}
Function CreateDir ($ dir = '')
{
$ this-> dir = $ dir? $ DIR: $ this-> DIR;
IF (! is_dir ($ this-> DIR))
{
$ TEMP = EXPLODE ('/', $ this-> DIR);
$ CUR_DIR = '';
For ($ i = 0; $ i { $ CUR_DIR. = $ TEMP [$ I]. '/'; IF (! is_dir ($ CUR_DIR)) { @mkdir ($ CUR_DIR, 0777); } } } } Function getDir ($ dirName = ', $ time = 0) { $ this-> time = $ TIME? $ TIME: $ THIS-> TIME; $ this-> dirname = $ dirname: $ this-> dirname; Switch ($ this-> dirtype) { Case 'Name': IF (Empty ($ this-> Dirname)) $ this-> DIR = $ this-> rootdir; Else $ this-> DIR = $ this-> rootdir. '/'. $ this-> dirname; Break; Case 'Year': $ this-> DIR = $ this-> rootdir. '/'. Date ("y", $ this-> time); Break; Case 'Month': $ this-> DIR = $ this-> rootdir. '/'. Date ("Y-M", $ this-> time); Break; Case 'Day': $ this-> DIR = $ this-> rootdir. '/'. Date ("Y-M-D", $ this-> time); Break; } $ this-> createdir (); Return $ this-> DIR; } Function geturlname ($ URL = '') { $ this-> URL = $ URL? $ URL: $ THIS-> URL; $ filename = basename ($ this-> URL); $ filename = expende (".", $ filename); Return $ filename [0]; } Function geturlQuery ($ URL = '') { $ this-> URL = $ URL? $ URL: $ THIS-> URL; $ dURL = PARSE_URL ($ this-> URL); $ dURL = EXPLODE ("&", $ dURL [query]); Foreach ($ DURL AS $ SURL) { $ GURL = EXPLODE ("=", $ surl); $ eURL [] = $ GURL [1]; } Return Join ("_", $ Eur1; } Function GetName ($ URL = ', $ TIME = 0, $ DIRNAME =' ') { $ this-> URL = $ URL? $ URL: $ THIS-> URL; $ this-> dirname = $ dirname: $ this-> dirname; $ this-> time = $ TIME? $ TIME: $ THIS-> TIME; $ this-> getdir (); Switch ($ this-> nametype) { Case 'Name': $ filename = $ this-> geturnname (). '. htm'; $ this-> name = $ this-> DIR. '/'. $ filename; Break; CASE 'TIME': $ this-> name = $ this-> dir. '/'. $ this-> time. '. HTM'; Break; Case 'Query': $ this-> name = $ this-> dir. '/'. $ this-> geturlQuery (). '. htm'; Break; Case 'NameQuery': $ this-> name = $ this-> dir. '/'. $ this-> geturnName ().'- '. $ this-> getURLQuery ().'. htm '; Break; Case 'Nametime': $ this-> name = $ this-> dir. '/'. $ this-> geturnname ().'- '. $ this-> time.'. htm '; Break; } RETURN $ THIS-> Name;} Function CreateHTML ($ URL = ', $ TIME = 0, $ DIRNAME =', $ HTMLNAME = '') { $ this-> URL = $ URL? $ URL: $ THIS-> URL; $ this-> dirname = $ dirname: $ this-> dirname; $ this-> time = $ TIME? $ TIME: $ THIS-> TIME; IF (EMPTY ($ HTMLNAME)) $ this-> getname (); Else $ this-> name = $ dirname. '/'. $ htmlname; $ Content = File ($ this-> URL) OR Die ("Failed to Open THE URL". $ this-> URL. "!") ;; $ Content = Join ("", $ content); $ fp = @ fopen ($ this-> name, "w") OR Die ("Failed to Open THE FILE". $ this-> name. "!"); IF (@fwrite ($ FP, $ Content)) Return True; Else Return False; Fclose ($ fp); } Function deletehtml ($ URL = '', $ TIME = 0, $ DIRNAME = '') { $ this-> URL = $ URL? $ URL: $ THIS-> URL; $ this-> time = $ TIME? $ TIME: $ THIS-> TIME; $ this-> getname (); IF (@unlink ($ this-> name)) Return True; Else Return False; } / ** * Function :: deletedir () * Delete the directory * @Param $ FILE directory name (without /) * @Return * / Function deleteDir ($ file) { IF (file_exists ($ file)) { IF (IS_DIR ($ file)) { $ Handle = OpenDir ($ file); While (false! == ($ filename = readdir ($ handle))) { IF ($ filename! = "." && $ filename! = "..") $ this-> deletedir ($ file. "/". $ filename); } CloseDir ($ handle); Rmdir ($ file); Return True; } Else { Unlink ($ file); } } } }