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内容如下:

QQ截图20181020102433.png


运行结果如下:

QQ截图20181020102459.png

QQ截图20181020102609.png