亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php 在文件指定行插入數(shù)據(jù)的代碼

 更新時(shí)間:2010年05月08日 19:26:49   作者:  
對(duì)于php文件操作那么關(guān)于在指定的位置插入數(shù)據(jù)就比較復(fù)雜了,下面我們就來看看關(guān)系在文件指定行插入數(shù)據(jù)實(shí)例吧。
復(fù)制代碼 代碼如下:

$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;
}
//在多數(shù)據(jù)我們存儲(chǔ)數(shù)據(jù)都是用數(shù)據(jù)庫教程來操作,上面我們就是把數(shù)據(jù)以X格式存在文本中了,現(xiàn)在我要像操作數(shù)據(jù)庫一樣的,想刪除那行就那行,保存數(shù)據(jù)也一樣,怎么讀取第幾行就第幾行了,所以我就寫出來了php 在文件指定行插入數(shù)據(jù)實(shí)例哦。
?>

$iLine:為第幾行,$index為第幾個(gè)字符之前

相關(guān)文章

最新評(píng)論