Help write a program. The meaning is this: there is a file file.txt, there is a script index.php
In the text file itself there are lines of the form:
line1
line2
line3
It is necessary to make the file update after launching the script, and there the lines themselves are of the following form:
"String1"
"String2"
"String3"

That is, quotation marks were inserted at the beginning and end of the line. And the first word of the line began with a capital letter.

    1 answer 1

    $str = file_get_contents('file.txt'); $arr = explode(' ', $str); foreach($arr as $k=>&$word){ $word = '"' . ucfirst($word) . '"'; } file_put_contents('file.txt', implode(' ', $arr)); 

    Ideone.com

    • hmm ... it changes only one line ... and put quotes not in lines but across the text in the file - skarui
    • 3
      @skarui, well, you have the foundation, the rest yourself, you are a programmer. - Opalosolo
    • $ arr = explode ('', $ str); => $ arr = explode ("\ n", $ str); \ n - a newline character - terantul
    • and uc_first -> dances with mb_strtoupper() and the first character. - etki
    • If the string is one word, then you can change the first character: [ php.net/manual/ru/function.mb-convert-case.php[[1] [1]: php.net/manual/ru/function.mb -convert-case.php - Stuf