Most of the file functions have been touched before. Here are just a few important ones:
resourcefopen(string$filename ,string $mode[,bool$use_include_path= false[,resource$context]] ) //Open the file, there are read-only, write-only, read-write mode
int filesize(string $filename ) // Get the size of the fileintfwrite(resource$handle ,string $string[,int$length] ) //Write file
stringfread(resource$handle ,int $length) //Read files, you can read binary filesboolunlink(string$file name[, resource$context] ) //Delete files
More and more detailed content: http://php.net/
Simple type:
<?php $in="tt.txt"; $fp=fopen($in,"r"); $get=fread($fp,filesize($in)); $fp=fopen("out.htm","w"); fwrite($fp,$get); fclose($fp); ?>
Generate multiple files in a loop, use 3 txt files to generate 3 htm files (Equivalent to conversion):
Problems encountered:
Warning: fopen(michael jordan——Killer.htm): failed to open stream: Invalid argument
Encoding problem, the generated file was indeed successful, but The file name is garbled, so the returned result is that the path does not exist. Just change it to English.
<?php $txtArray=array(array("t1.txt","fly.htm"),array("t2.txt","killer.htm"), array("t3.txt","chamption.htm")); foreach ($txtArray as $id=>$value){ $filename=$value[0]; $title=$value[1]; $fp=fopen($filename,"r"); $get=fread($fp,filesize($filename)); $fp=fopen($title,"w"); fwrite($fp,$get); unlink($filename); //删除源文件 } fclose($fp); ?>
<?php $txtArray=array(array("t1.txt","michael jordan——飞翔.htm"),array("t2.txt","michael jordan——杀手.htm"), array("t3.txt","michael jordan——首冠.htm")); foreach ($txtArray as $id=>$value){ $filename=$value[0]; $title=$value[1]; $fp=fopen($filename,"r"); $get=fread($fp,filesize($filename)); $fp=fopen($title,"w"); fwrite($fp,$get); //unlink($filename); //删除源文件 } fclose($fp); ?>
The above introduces how to generate HTML files with PHP, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.