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内容如下: 运行结果如下: 转载于:https://blog.51cto.com/suyanzhu/2306723