file_put_contents($file,$content)的問題

來源:互聯網
上載者:User
file_put_contents(“a.txt”,$content);//這樣可以成功
file_put_contents(“啊.txt”,$content);//這樣就失敗了 什麼原因呢?


回複討論(解決方案)

報什麼錯? 可以的話盡量別用中文命名檔案名稱。

什麼都沒有報 直接空白

有錯誤……
Warning: file_put_contents(啊.txt): failed to open stream: Invalid argument in E:\test\search\index1.php on line 5

什麼都沒有報 直接空白


有錯誤……
Warning: file_put_contents(啊.txt): failed to open stream: Invalid argument in E:\test\search\index1.php on line 5

你的系統是windows系統吧,windows系統預設編碼是gbk,所以你要設定你的php檔案為gbk編碼。
可以用notepad++設定編碼格式為ANSI 格式

檔案名稱避免使用中文,因為window與linux的字元集是不同的。

php 曾再三聲明:對 unicode 字元集不能很好的處理
所以最好不要用中文檔案名稱和路徑
一定要使用的話,需要使用與作業系統一致的字元集

代碼前面加上 setlocale(LC_ALL, "");試試?

謝謝各位,我已經在網上找到解決的方法

應該就是樓上說的編碼轉化成作業系統的編碼吧

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.