index.php代碼如下:
<?php
header("Content-type: text/html; charset=utf8");
// 將整個文件newfile.txt的內容讀入一個字符串$str
$str=file_get_contents('newfile.txt');
// 把每個單詞的首字符轉換爲大寫
$str=ucwords($str);
// 將一個字符串$str寫入文件doc.txt
file_put_contents('doc.txt',$str);
newfile.txt內容如下:
運行結果如下: