How does PHP execute a dynamic page to the cache and then generate a static page?
In ASP, the open method of the XMLHTTP object is usually used to open a dynamic page for execution. the static html code generated after the dynamic page is executed can be a adodb. the stream object is saved and then written to a text file.
In PHP, you can use ob_start to open the cache, so that the string is first written to the cache, and then the content in the cache is written to a text file. The problem is, how does PHP execute a dynamic page, in some articles, we use header ("location: adminnews. what should I do in php "example?
Ob_start (); // open the buffer
Echo "Hello \ n"; // output
Header ("location: adminnews. php"); // redirects the browser to index. php.
$ CacheStr = ob_get_contents ();
$ Handle = fopen ("jb51.html", "w ");
Fwrite ($ handle, $ cacheStr );
Ob_clean ();
?>
Reply to discussion (solution)
Ob_start (); // open the buffer
Echo "Hello \ n"; // output
Include ("adminnews. php"); // load and run
$ CacheStr = ob_get_contents ();
$ Handle = fopen ("jb51.html", "w ");
Fwrite ($ handle, $ cacheStr );
Ob_clean ();
Use $ wstr = file_get_contents ('http: // www.baidu.com '). you can use this function to execute a URL address.
Is file_get_contents a built-in function in php?
Is file_get_contents a built-in function in php?
Yes, see file_get_contents
Is file_get_contents a built-in function in php?
Yes. you can refer to the manual for reference.
File_get_contents can get the result of adminnews. php execution.
File_get_contents can get the result of adminnews. php execution.
I tried it. I can't use it to get adminnews. php source code, rather than adminnews. the php execution result is the html code generated after execution, rather than the original php code ..
Ob_start (); // open the buffer
Echo "Hello \ n"; // output
$ CacheStr = file_get_contents ("adminnews. php ");//
$ Handle = fopen ("jb51.html", "w ");
Fwrite ($ handle, $ cacheStr );
Ob_clean ();
?>
File_get_contents can get the result of adminnews. php execution.
I tried it. I can't use it to get adminnews. php source code, rather than adminnews. the php execution result is the html code generated after execution, rather than the original php code ..
Ob_start (); // open the buffer
Echo "Hello \ n"; // output
$ CacheStr = file_get_contents ("adminnews. php ");//
$ Handle = fopen ("jb51.html", "w ");
Fwrite ($ handle, $ cacheStr );
Ob_clean ();
?>
How did you access it through the browser? in file_get_contents, enter the address
File_get_contents can get the result of adminnews. php execution.
I tried it. I can't use it to get adminnews. php source code, rather than adminnews. the php execution result is the html code generated after execution, rather than the original php code ..
Ob_start (); // open the buffer
Echo "Hello \ n"; // output
$ CacheStr = file_get_contents ("adminnews. php ");//
$ Handle = fopen ("jb51.html", "w ");
Fwrite ($ handle, $ cacheStr );
Ob_clean ();
?>
The example I gave is so obvious that I still don't understand it?
Now, adminnews. php is written as an absolute path. it is not executed if only the file name is written.