Php generates static page html page code

Source: Internet
Author: User

  1. <? Php
  2. Header (Content-type: text/html; charset = UTF-8 );
  3. If (! Function_exists (file_get_contents) {// if the system does not have the file_get_contents () function
  4. Function file_get_contents ($ file) {// write the file_get_contents () function by yourself
  5. $ Fp = fopen ($ file, r );
  6. $ Content = fread ($ fp, filesize ($ file ));
  7. Fclose ($ fp );
  8. Return $ content;
  9. }
  10. }
  11. $ Tmp_file = template.html; // Template File
  12. $ Content = file_get_contents ($ tmp_file); // obtain the Template File content
  13. $ Title = title; // the value to be replaced by the template variable title.
  14. $ Text = text; // The value of the template variable text to be replaced
  15. $ Content = str_replace (<{title}>, $ title, $ content); // Replace the template variable title
  16. $ Content = str_replace (<{text}>, $ text, $ content); // Replace the template variable text
  17. // Echo $ content; // display the content of the replaced Template File
  18. MakeHtml(news.html, $ content); // write the generated static file to the news.html file.
  19. Echo <a href = "news.html" target = "_ blank"> View files </a>;
  20. Function MakeHtml ($ file, $ content ){
  21. $ Fp = fopen ($ file, w );
  22. Fwrite ($ fp, $ content );
  23. Fclose ($ fp );
  24. }
  25. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.