Created
October 4, 2009 14:56
-
-
Save dwiash/201425 to your computer and use it in GitHub Desktop.
nulis ke file pake PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// kasih nama file yg jadi sasaran buat nulisnya | |
$nama_file = 'test.txt'; | |
// ini text yang mau dimasukin ke dalem filenya | |
$text_yang_mau_dimasukin = "ini textnya, ini textnya, ini textnya, ini textnya, ini textnya, "; | |
// pertama buka filenya dulu, kalo filenya ngga ada, bakal dibikin secara otomatis | |
// begitu buka file, ada variable yang dikasih nama $handle yg berfungsi sbg RESOURCE HANDLER, | |
// jadi ntar segala operasi (misalnya nulis) bakal berhubungan sama variable ini | |
if (!$handle = fopen($nama_file, 'w')) { | |
echo "Gagal Buka file"; // pesan error | |
exit; // kalo gagal, langsung keluar biar perintah dibawah ngga perlu dikerjain lagi | |
} | |
// kalo udh berhasil buka file, langsung tulis aja | |
if (fwrite($handle, $text_yang_mau_dimasukin) === FALSE) { | |
echo "Gagal nulis"; // ini pesan error | |
exit; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment