如何在php中插入文件中间的一些文本,是一种可用于在文件内容中间插入文本的方法.
不完全是文件的中间.,搜索关键字,然后我们需要在内容之前或之后插入,
如果搜索关键字在文件中找到多个时间,则会发生wat
使用fopen,fseek,ftell,fwrite,和fclose:
// Create the file handler
$file = fopen("filename", "r+");
// Seek to the end
fseek($file, SEEK_END, 0);
// Get and save that position
$filesize = ftell($file);
// Seek to half the length of the file
fseek($file, SEEK_SET, $filesize / 2);
// Write your data
fwrite($file, "Data");
// Close the file handler
fclose($file);
Run Code Online (Sandbox Code Playgroud)