標題: PHP修改檔案一問
 hopkins
 0058431
Rank: 3Rank: 3Rank: 3

頭銜: Conqueror

帖子: 147

精華: 0

積分: 1710 點

現金: -597 元

存款: 116 元

閱讀權限: 20

註冊: 2006-11-20

狀態: 離線
 
發表於 2008-7-22 15:06  資料  個人空間  短消息  加為好友 
PHP修改檔案一問

請問PHP怎樣可以修改檔案?
像這樣:
1.txt
1234567890
abcdefghijklmn
hallo

index.php :
修改1.txt,由1.txt的hallo變為hello,其他內容不變

那麼index.php要打甚麼PHP語法才能修改到1.txt呢?

唔該!




 AL8 Forum © All rights reserved.
頂部
 expgame
 0056311
Rank: 4Rank: 4Rank: 4Rank: 4

頭銜: Lord

帖子: 326

精華: 0

積分: 410 點

現金: 0 元

存款: 811 元

閱讀權限: 25

註冊: 2006-10-27

來自: 香港

狀態: 離線
 
發表於 2008-7-22 19:04  資料  個人空間  主頁 短消息  加為好友  添加 expgame 為MSN好友 通過MSN和 expgame 交談
<?php
$filename = '1.txt';

//READ FILE
$fd = fopen($filename, "r");
$jst = fread($fd, filesize($filename));
fclose($fd);

//REPLACE hallo TO hello
$jssok = str_replace('hallo', 'hello', $jst);
//如果唔得就將str_replace改做ereg_replace

//SAVE FILE
$fpt = fopen($filename ,"w+");
fputs($fpt, $jssok);
fclose($fpt);

//expgame @ AL8 Forum
?>


我未試過, 唔知得唔得 - -




 AL8 Forum © All rights reserved.
頂部


網頁空間由 I-SERVICES 提供
當前時區 GMT+8, 現在時間是 2008-12-5 08:58