Fileのデータを1行ずつ処理させる



データベースを使わずにデータを蓄積する際使えるかも。


勉強用なのでコピーして使う方は自己責任でお願いします。


必要なファイル



  • root

    • index.php

    • datafile.txt




PHPファイル



<?php
class ImgLogEdit {
function ImgLog($FileType){
$fp = fopen ($FileType, "r"); //データファイルの読み込み
while (!feof ($fp)) {
$buffer = fgets($fp, 4096);
$array = split("-&",$buffer); //配列に挿入
echo $array[0] . "<br />\n"; //配列の読み出し
echo $array[1] . "<br />\n";
echo $array[2] . "<br />\n";
}
fclose ($fp);
}
}
$Obj = new ImgLogEdit;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$Obj->ImgLog('datafile.txt'); //データの出力('読み込みファイルの指定');
?>
</body>
</html>

データtxtファイル



20081216-&名前-&http://d.hatena.ne.jp/ryuichi1com/
20081216-&名前-&http://d.hatena.ne.jp/ryuichi1com/
20081216-&名前-&http://d.hatena.ne.jp/ryuichi1com/
20081216-&名前-&http://d.hatena.ne.jp/ryuichi1com/


もっと利便性の高くなるようにしないと。


Trackback(0)

Trackback URL:

Please Comments





Page Top