1. Home
  2. Docs
  3. PHP
  4. File,Dir 路徑和檔案
  5. 檔案讀取和寫入

檔案讀取和寫入

        // 資料來源:httpsss://www.w3schools.com/php/php_file_open.asp
        function File_Read($filename){
            $myfile = fopen($filename, "r") or die("Unable to open file!");
            $dat1=fread($myfile,filesize("webdictionary.txt"));
            fclose($myfile);
            return $dat1;
        }
    
        // 寫入檔案
        // 資料來源:httpsss://www.w3schools.com/php/php_file_create.asp
        function File_Write($filename,$txt){
            $myfile = fopen($filename, "w") or die("Unable to open file!");
            fwrite($myfile, $txt);
            fclose($myfile);
        }