CopyCode The Code is as follows: $ arrinsert = insertcontent ("array. php", "abcdef", 3, 10 );
Unlink ("array. php ");
Foreach ($ arrinsert as $ value)
{
File_put_contents ("array. php", $ value, file_append );
}
Function insertcontent ($ source, $ S, $ iline, $ index ){
$ File_handle = fopen ($ source, "R ");
$ I = 0;
$ Arr = array ();
While (! Feof ($ file_handle )){
$ Line = fgets ($ file_handle );
++ $ I;
If ($ I = $ iline ){
If ($ Index = strlen ($ line)-1)
$ Arr [] = substr ($ line, 0, strlen ($ line)-1). $ S. "N ";
Else
$ Arr [] = substr ($ line, 0, $ Index). $ S. substr ($ line, $ index );
} Else {
$ Arr [] = $ line;
}
}
Fclose ($ file_handle );
Return $ arr;
}
// In multi-data storage, data is stored in the database tutorial. In the above example, the data is stored in the text in the X format. Now I want to operate like a database, the row that you want to delete is the same as the row that stores the data. How to read the row that contains the row number is the same, so I wrote PHP to insert the data instance in the specified row of the file.
?>
$ Iline: the number of lines, $ index before the number of characters