Simple example of php generating html file

WBOY
Release: 2016-07-25 09:03:54
Original
941 people have browsed it
  1. $con = array(array("newtitle","newcontent"),array("newtitle2","newcontent2"));
  2. foreach($con as $id=>$ val)
  3. {
  4. $title = $val[0];
  5. $content = $val[1];
  6. $path = $id.'.htm';
  7. $fp = fopen("jia.htm", "r "); //Open the file in read-only mode
  8. $str = fread($fp, filesize("jia.htm")); //Read the file
  9. $str = str_replace("{title}", $title, $str); //Replace the content in the string
  10. $str = str_replace("{content}", $content, $str);
  11. fclose($fp); //Close the file
  12. $fpw = fopen ($path, "w"); //Open the file for writing
  13. fwrite($fpw, $str); //Write $str to the file
  14. fclose($fpw);
  15. echo "generate successfully!" ;
  16. }
  17. ?>
Copy code


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