Class create_html { Private $ template; // Template Private $ file_name; // File name Private $ array; // Data array Function _ construct ($ file_name, $ template, $ array ){ // Construct a class $ This-> template = $ this-> read_file ($ template, "r "); // Read the template file $ This-> file_name = $ file_name; $ This-> array = $ array; // Data $ This-> html (); // Generate html } Function html (){ // Generate html While (ereg ("{([0-9] +)}", $ this-> template, $ regs )){ // {1 }..... $ Num = $ regs [1]; // Obtain the sequence 1, 2, and 3. $ This-> template = ereg_replace ("{". $ num. "}", $ this-> array [$ num], $ this-> template ); // Replace the data with html content $ This-> write_file ($ this-> file_name, $ this-> template, "w + "); // Generate an HTML file } } Function read_file ($ file_url, $ method = "r "){ // Read the file $ Fp = @ fopen ($ file_url, $ method ); // Open the file $ File_data = fread ($ fp, filesize ($ file_url )); // Read file information Return $ file_data; } Function write_file ($ file_url, $ data, $ method ){ // Write a file $ Fp = @ fopen ($ file_url, $ method ); // Open the file @ Flock ($ fp, LOCK_EX ); // Lock the file $ File_data = fwrite ($ fp, $ data ); // Write a file Fclose ($ fp ); // Close the file Return $ file_data; } } # Example -------- # Read the email reply template ---------------------------- $ Title = "title "; $ Navigation = "browser "; $ Happy_origin = "author "; $ Name = "test2.htm "; $ Template = "default_tmp.php "; // Replace {1} {2} in the template $ Daytype = array (1 => $ title, 2 => $ navigation, 3 => $ happy_origin ); $ Htm = new Restore_email ($ template, $ daytype ); Echo $ htm-> pint (); ?> |