In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to generate html files by PHP". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
PHP generates html file 1, here is a method of using templates!
< ?php $fp = fopen ("templets.html","a"); if ($fp){ $fup = fread ($fp,filesize ("templets.html")); $fp2 = fopen ("html.shtml","w"); if ($fwrite ($fp2,$fup)){ $fclose ($fp); $fcolse ($fp2); die ("写入模板成功"); } else { fclose ($fp); die ("写入模板失败!"); } } ?> < ?php $fp = fopen ("templets.html","a"); if ($fp) { $fup = fread ($fp,filesize("templets.html")); $fp2 = fopen ("html.shtml","w"); if ($fwrite ($fp2,$fup)) { $fclose ($fp); $fcolse ($fp2); die ("写入模板成功"); } else { fclose ($fp); die ("写入模板失败!"); } } ?>Simply write the template into a file and save it as html.html
PHP generates html file 2 and generates html file name according to time
< ?php $content = "这是一个以日期时间为文件名 的静态生成网页的测试文件,文件名格式一 般为< font color=#ff0000>Year, month, day, hour, minute and second
.html
< /font>"
$datedate = date ('YmdHis')
$fp = fopen (date ('YmdHis'). '.html', "w")
/ / this function can be used to open the local or remote file'w'.
The file is opened by writing, and the file pointer points to the beginning.
And set the length of the original file to 0. If the file does not exist, a new file is created.
If (fwrite ($fp,$content)) {
/ / format is .int fwrite (int fp (file name)
String string (content), int [length]
(length); this function writes the string string to the file
On the pointer fp of the stream. If there is a specified length length
The specified length string is written, or until the end of the string.
Fclose ($fp); / / function is used to close open text
The pointer fp of the. True is returned for success and false for failure.
Die ("template written successfully")
}
Else {
Fclose ($fp)
Die ("failed to write template!")
}
Echo ($content)
? >
< ?php $content = "这是一个以日期时间为文件名 的静态生成网页的测试文件,文件名格式一般为 < font color=#ff0000>Year, month, day, hour, minute and second. Html
< /font>"
$datedate = date ('YmdHis')
$fp = fopen (date ('YmdHis'). '.html', "w")
/ / this function can be used to open the local or remote file'w'.
The file is opened by writing, and the file pointer points to the beginning.
And set the length of the original file to 0. If the file does not exist, a new file is created.
If (fwrite ($fp,$content))
{/ / format is .int fwrite (int fp (file name)
String string (content), int [length] (length))
This function writes the string string to the pointer fp of the file stream.
If there is a specified length length, the specified length string will be written
Or write to the end of the string. Fclose ($fp)
The / / function is used to close the pointer fp of an open file.
True is returned for success and false for failure.
Die ("template written successfully");}
Else {fclose ($fp); die ("failed to write template!")
}
Echo ($content);? >
PHP generates html file 3. Here is a way to convert the file name
< ?php $s_fname = "93e.php"; $o_fname = "93e.htm"; ob_end_clean(); ob_start(); include($s_fname); $length = ob_get_length(); $buffer = ob_get_contents(); $buffer = eregi_replace("r","",$buffer); ob_end_clean(); $fp = fopen($o_fname,"w+"); fwrite($fp,$buffer); fclose($fp); ?> < ?php $s_fname = "93e.php"; $o_fname = "93e.htm"; ob_end_clean(); ob_start(); include($s_fname); $length = ob_get_length(); $buffer = ob_get_contents(); $buffer = eregi_replace("r","",$buffer); ob_end_clean(); $fp = fopen($o_fname,"w+"); fwrite($fp,$buffer); fclose($fp); ?>This is the end of the content of "how PHP generates html files". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.