Web/PHP
파일 읽고 쓰기 - 간단한 데이터를 다룰 때
WakaraNai
2021. 10. 9. 22:35
728x90
반응형
DB까지 접근할 필요 없는 간단한 설정값들은 파일에 저장해놓고 쓰기 편하다.
- Connect the target file with a 'file handle'
- $fp = fopen("memo1.txt", "r");
- Read / Write
- Close
텍스트 파일 읽기
abc.txt
abcdefg
hijklmnop
qrstuv
wxyz
readfile.txt
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<?php
$fp = @fopen("abc.txt", "r") or die("Error!\n");
while (!feof($fp)) {
echo fgets($fp)."<BR>\n";
}
fclose($fp);
?>
</body>
</html>
728x90
반응형