PHP 파일 쓰기

IT위키
계발자 (토론 | 기여)님의 2023년 2월 18일 (토) 11:43 판 (새 문서: == 파일 열기 == * 쓰기 모드(w)로 파일을 연다. * fopen을 사용한다. <syntaxhighlight lang="php"> <?php $myFile = fopen("testfile.txt", "w") or die("Unable to open file!"); ?> </syntaxhighlight> == 파일 쓰기 == * fwrite를 이용해 파일을 쓴다. <syntaxhighlight lang="php" line="1"> <?php $myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); $txt = "John Doe\n"; fwrite($myfile, $txt); $txt = "Jane Doe\n"; fwrite($...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

파일 열기

  • 쓰기 모드(w)로 파일을 연다.
  • fopen을 사용한다.
<?php
    $myFile = fopen("testfile.txt", "w") or die("Unable to open file!");
?>

파일 쓰기

  • fwrite를 이용해 파일을 쓴다.
<?php
    $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
    $txt = "John Doe\n";
    fwrite($myfile, $txt);
    $txt = "Jane Doe\n";
    fwrite($myfile, $txt);
    fclose($myfile);
?>
  • 결과는 아래와 같다. (newfile.txt)
John Doe
Jane Doe