Thao tác với file trong PHP
1. đọc tất cả các dòng trong file :
<?php
$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
while(!feof($myfile)) {
echo fgets($myfile) . "<br>";
}
fclose($myfile);
?>
$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
while(!feof($myfile)) {
echo fgets($myfile) . "<br>";
}
fclose($myfile);
?>
2. đọc tất cả các kí tự trong file :
<?php
$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
while(!feof($myfile)) {
echo fgetc($myfile);
}
fclose($myfile);
?>
$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
while(!feof($myfile)) {
echo fgetc($myfile);
}
fclose($myfile);
?>
3. đọc file theo hàng và lưu vào mảng 1 chiều :
<?php
$mang = array();
$myfile = fopen("sms/thoigian/$entry", "r") or die("Unable to open file!");
while(!feof($myfile)) {
$sms = fgets($myfile);
$mang[]=$sms;
}
fclose($myfile);
foreach($mang as $value)
{
echo $value."<br>";
}
?>
$mang = array();
$myfile = fopen("sms/thoigian/$entry", "r") or die("Unable to open file!");
while(!feof($myfile)) {
$sms = fgets($myfile);
$mang[]=$sms;
}
fclose($myfile);
foreach($mang as $value)
{
echo $value."<br>";
}
?>
không đơn giản chút nào
Trả lờiXóatư vấn bảo hiểm xã hội
luật bảo hiểm xã hội