PHP tutorial Inserting a data instance on a file-specified line
For PHP file operations so it is more complicated to insert data at a specified location, let's look at the relationship Insert data instance in the specified row of the file.
$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 the majority of our data is stored in the database tutorial, we have the data in the X format in the text, and now I want to do the same as the database, I want to delete the row that row, save the data also, how to read the first few lines on the first line, so I wrote the PHP Inserts a data instance into the specified row of a file.
?>
$iLine: For the first few lines, $index before the first character
http://www.bkjia.com/PHPjc/444951.html www.bkjia.com true http://www.bkjia.com/PHPjc/444951.html techarticle PHP Tutorial Inserts a data instance into a file specified line for PHP file operations so about inserting data at a specified location is more complicated, and let's look at the relationship in the file specifying the line interpolation ...