iT邦幫忙

0

php寫字元到檔案裡

php

大家好

請問一個問題
假設
一個檔案的檔案內容是"abcd efght"
我要寫'Y'字元到第5個位置
檔案內容變成"abcdYefght"
php有沒有函式或方法可以寫呢?
謝謝大家^^

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

8
fillano
iT邦超人 1 級 ‧ 2010-04-11 23:41:38
最佳解答

http://tw2.php.net/manual/en/function.substr-replace.php

這些基本的函數,查一查手冊就找得到,把網址記一記吧。

2
godstamp
iT邦新手 3 級 ‧ 2010-04-13 21:39:22

假設檔名是.. ex.txt
程式碼如下...

$file_name = 'ex.txt';
$str = file_get_contents($file_name);
$str = explode(' ',$str);
$str = implode('Y',$str);
file_put_contents($file_name,$str);

以上..是針對例子寫的..
沒測試過,應該是沒有問題...
都是一些基本函式的運用而已..

我要發表回答

立即登入回答