contact

Contact Person
Pin BB : 5AB31960
SMS : 082288467823
WA : 081275371724
call : 081275668074


Operasi Dasar File.txt dengan PHP

Posted in PHP MYSQL / i Life at 11 Februari 2016 With 0 Comments

Kita dapat Memanipulasi File .txt , terkadang seorang programer membutuhkan file .txt dalam mengembangkan project yang dibuatnya... Kali ini suckittrees dot com akan berbagi script / operasi dasar dalam mengelola file.txt

Berikut Operasi Dasar file.txt dengan PHP



1. CreateFile .txt

<?php
$file = 'file.txt';
//To Create File
$fp = fopen($file, 'w') or die('Cannot open file:  '.$file);
if($fp){
echo "file created successfully";
}
fclose($fp);
?>

2. Write File txt

<?php
//To Write to the file
$file = 'file.txt';
$fp = fopen($file, 'w') or die('Cannot open file:  '.$file);
$data = 'Line1:This is Line1 data';
fwrite($fp, $data);
fclose($fp);
?>

3. Read File txt

<?php
//To Read File
$file = 'file.txt';
$fp = fopen($file, 'r');
$data = fread($fp,filesize($file));
echo $data;
?>

4. Append File txt

<?php
//append to the file
$file = 'file.txt';
//opening a file in append mode.
$fp = fopen($file, 'a') or die('Cannot open file:  '.$file);
$data = 'Line no.1: Data on first line'."n";
fwrite($fp, $data);
fclose($fp);
?>

5. Delete File txt

<?php
//deleteing file from hard desk
$file = 'file.txt';
unlink($file);
?>

Artikel Terkait

Diskusi