ホームページ バックエンド開発 PHPチュートリアル php はデータベース プログラムとして txt テキスト ファイルを使用します_PHP チュートリアル

php はデータベース プログラムとして txt テキスト ファイルを使用します_PHP チュートリアル

Jul 20, 2016 am 11:07 AM
define php txt する データベース 書類 文章 使用 プログラム

define ("tblPath",".");
define ("exten",".php");
define ("fileHead","これclass txtTbl");
class txtTbl {
var $innerName=""; //データベース名
var $innerCount; //データベースレコード数
var $innerFields; //データベースフィールドリスト配列
var $inner_F_Count ; //データベースのフィールド数
var $fullName; // 完全なファイル名
var $isModify = false; //現在のレコードが変更されているかどうか
var $fileModify = false; $innerRecorders; // データベース レコードの配列
var $curLine; // 現在のレコードの配列
var $stringDel; // データベース レコード間の区切り文字
var $ sprt2; //データベースフィールド間の区切り文字
var $innerBof = true;
var $innerEof = false;


function create($tblName,$fields,$sprt1="<---txtTbl-- - >n",$sprt2="<---txtTbl--->"){

if (empty($tblName)){

echo "textDateBase ファイル名が指定されていません。";

return false;
}
$fullName = tblPath.$tblName.exten;
if (file_exists($fullName)){
echo "textDateBase ファイルはすでに存在します。";
return false;
}
if(empty($fields)) {
echo "フィールド リストの配列が無効です。";
return false;
}
$cont = implode($sprt2,$fields);
$cont = fileHead."n".$cont;
$fp = fopen ( $fullName,"w");
fwrite($fp,$cont);
fclose($fp);
return true;
}

function drop($tblName,$sprt1="<---txtTbl--->n",$sprt2="<---txtTbl--->"){
if (empty($tblName )){
echo "textDateBase ファイル名が証明されていません。";
return false;
}
if (!empty($this->innerName)){
echo "現在のファイルが閉じられていません。閉じてもう一度お試しください。 .";
return false;
}
$fullName = tblPath.$tblName.exten;
if (!file_exists($fullName)){
echo "textDateBase ファイルが存在しません。";
return false;
}
$ fp = fopen($fullName,"r");
if (!feof($fp)){
$readFromFile = fgets($fp);
}
if ($readFromFile!=fileHead."n"){
fclose($fp);
echo "有効な textDataBase ファイルではありません。(先頭が無効です。)"."n";
return false;
}
$readFromFile = "";
if (!feof($fp) ) $readFromFile.= fgets($fp);
fclose($fp);
$readFromFile = トリム($readFromFile);
if (empty($readFromFile)){
echo "有効な textDataBase ファイルではありません。(できません)フィールドの定義が見つかりません。)";
return false;
}
$cont = fileHead."n".$readFromFile;
$fp = fopen($fullName,"w");
fwrite($fp,$cont) ;
fclose($fp);
return true;
}


function open($tblName,$sprt1="<---txtTbl--->n",$sprt2="<--- txtTbl--->"){
if (empty($tblName)){
echo "textDateBase ファイル名が証明されていません。";
return false;
}
if (!empty($this->innerName) ){
echo "現在のファイルが閉じられていません。閉じてもう一度お試しください。";
return false;
}
$this->fullName = tblPath.$tblName.exten;
if (!file_exists($this-> ;fullName)){
echo "textDateBase ファイルが存在しません。";
return false;
}
$fp = fopen($this->fullName,"r");
if (!feof($fp)) {
$readFromFile = fgets($fp);
}
if ($readFromFile!=fileHead."n"){
fclose($fp);
echo "有効な textDataBase ファイルではありません。(ヘッドが無効です。) "."n";
return false;
}
$readFromFile = "";
while (!feof($fp)) $readFromFile.= fgets($fp);
fclose($fp);
$readFromFile = rim($readFromFile);
if (empty($readFromFile)){
echo "有効な textDataBase ファイルではありません。(フィールド定義が見つかりません。)";
return false;
}
$this->innerRecorders = explode($sprt1,$readFromFile);
$this->innerCount = count($this->innerRecorders) - 1;
$this->innerFields =explode($sprt2,$this->innerRecorders[0 ]);
$this->innerFieldsCount = count($this->innerFields);

$this->innerName = $tblName;
$this->sprt1 = $sprt1;
$this-> sprt2 = $sprt2;

if ($this->innerCount==0){
$this->curLine = 0;
$this->innerEof = true;
}else{
$this-> curLine = 1;
// if ($this->innerCount==1) $this->innerEof = true;
if (!$this->initRec()) return false;
}

return true ;
}

function close(){
if (empty($this->innerName)) return true;
//save edit
$isModify= false;
if ($this->isModify){
$ this->saveModify();
$isModify= true;
}
if(isset($this->stringDel)){
$isModify= true;
$delNo=explode(",",$this-> ;stringDel);
foreach($delNo as $no){
$no= (整数) $no;
unset($this->innerRecorders[$no]);
}
}
if ($isModify|| $this->fileModify){
$recorders= implode($this->sprt1,$this->innerRecorders);
$recorders= fileHead."n".$recorders;
$fp = fopen($this ->fullName,"w");
fwrite($fp,$recorders);
fclose($fp);
}
$this->innerName="";
unset($this->innerRecorders) ;
unset($this->curArray);
}

function next(){
if ((!$this->innerEof)&&(!empty($this->innerName))){
if($this->curLine==$this->innerCount ){
$this->innerEof = true;
return true;
}
$this->saveModify();
$this->curLine++;
if ($this->innerBof) $this-> ;innerBof = false;
$this->initRec();
}
return false;
}

function prev(){
if ((!$this->innerBof)&&(!empty($this- >innerName))){
$this->saveModify();
$this->curLine--;
if ($this->curLine == 1)
$this->innerBof = true;
if ($this->innerEof) $this->innerEof = false;
$this->initRec();
}
}

function first(){
if ($this->innerBof| |empty($this->innerName))
return false;
$this->saveModify();
$this->curLine = 1;
$this->innerBof= true;
$this-> ;innerEof = false;
$this->initRec();

}

function end(){
if ($this->innerEof||empty($this->innerName))
return false;
$this->saveModify();
$this->saveModify();
$this->gt;curLine = $this->gt;innerCount;
$this->innerEof= true;
$this->gt;innerBof = false;
$this-> ;initRec();

}

function eof(){
if (empty($this->innerName)){
return false;
}else return $this->innerEof;

}


function bof (){
if (empty($this->innerName)){
return true;
}else return $this->innerBof;

}


function recNo(){
return $this->curLine; : this->inner_F_Count;

}


function getValue($field){
if ($this->curLine==0||empty($this->innerName)){

echo "現在を読み取れませんレコード、使用されていない可能性があります。またはレコードがありません。";

return false;
}
$field= $this->chkField($field);
if ($field==-1){
return false;

}

return $this->curArray[$field];
}


function setValue($field,$value){
if ($this->curLine==0||empty($this->gt;innerName) )){
echo "現在のレコードを読み取れません。使用されていない、またはレコードがない可能性があります。";
return false;
}
$field= $this->chkField($field);
if ($field= =-1){

return false;

}
$this->curArray[$field]= $value;
$this->modify= true;
}

function display($shownon=0,$sprt1) ="",$sprt2="",$sprt3="",$sprt4=""){
echo $sprt3;
foreach($ this->curArray as $v){
if($shownon==1&&empty($v)) $v= "noValue";
echo $sprt1.$v.$sprt2;
}
echo $sprt4;
}

function location($field,$keyValue){
$field=$this->chkField($field);
if ($field==-1) return false;
for($i=$this-> curLine;$i<=$this->innerCount;$i++){
if($this->curArray[$field]==$keyValue){
return true;
}
$this->next( );
}
return false;
}

function del($recNo=-1){
if($this->curLine==0) return false;
$vartype= gettype($recNo);
if ($vartype!="integer"){
echo "del error:check ur para type.";
return false;
}
if ($recNo==-1){
$recNo=$this->curLine ;}
elseif ($recNo>$this->innerCount||$recNo<1){
echo "del error:out over the range.";
return false;
}
if (!$this-> chkDel($recNo)){
if(isset($this->stringDel)){
$this->stringDel.=(','.$recNo);
}else $this->stringDel = ( string) $recNo;
}else return false;
}

function append($fields=""){
$this->saveModify();
for($i=1;$i<=$this- >innerFieldsCount;$i++)
$newRec[] = "";
if(!empty($fields)){
foreach($fields as $k=>$v){
$k= $this-> ;chkField($k);
if ($k==-1){
return false;
}
$newRec[$k]= $v;
}
}
$this->innerCount++;
$this ->curLine = $this->innerCount;
$this->innerBof = false;
$this->innerEof = true;
unset($this->curArray);
$this->curArray = &$newRec;
$this->isModify = true;
}


//保存修改
function saveModify(){
if($this->isModify){
$this->innerRecorders[ $this->curLine]= implode($this->sprt2,$this->curArray);
$this->isModify = false;
$this->fileModify= true;
}
}

//当指针発行变化時,初初化当前记录数组
function initRec(){
$this->curArray =explode($this->sprt2,$this->innerRecorders[$this->curLine] );
if (count($this->curArray)!=$this->innerFieldsCount){
echo "現在のレコーダーのフィールド数が Table's.n ファイルと等しくありません。ファイルは閉じられます。";
$this->close ();
return false;
}
return true;
}


//输出当前记录情報,设计调试用
function ddisplay(){
if ($this->innerCount==0) return false ;
foreach($this->innerFields as $v) echo $v."----";
echo "
";
foreach($this->curArray as $v) echo $v ."---";
}

//检查记录否か否被删除
function chkDel($key){
if (empty($key)&&$key!=0){
echo "キーは指定されていません.";
return false;
}
if (!isset($this->stringDel)){
return false;
}
if (ereg("(^|,)".$key."(,| $)",$this->stringDel)){
return true;
}
return false;
}

//检查提交フィールド名が合法かどうか。
function chkField($field){
if (empty($field)&&($field!=0)){
echo "フィールドが指定されていません。";
return - 1;
}
$vartype = gettype($field);
switch ($vartype) {
case "integer":
if ($field>=$this->innerFieldsCount){
echo "フィールドは次より大きいですfieldcount";
return -1;
}elseif($field<0){
echo "フィールドは 0 未満です";
return -1;
}
return $field;
case "string":
foreach ( $this->innerFields as $k=>$v) if ($field==$v) return $k;
echo "フィールド名が見つかりません。";
return -1;
デフォルト:
echo "フィールドが無効です。";
return -1;
}
}

}


www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/444999.html技術記事 (tblPath,.) を定義します。 (exten,.php) を定義します。定義 (fileHead,? echo ようこそ!?。このファイルはクラス txtTbl 専用);クラス txtTbl { var $innerName=; //データ库名 var $innerCo...
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Dec 24, 2024 pm 04:42 PM

PHP 8.4 では、いくつかの新機能、セキュリティの改善、パフォーマンスの改善が行われ、かなりの量の機能の非推奨と削除が行われています。 このガイドでは、Ubuntu、Debian、またはその派生版に PHP 8.4 をインストールする方法、または PHP 8.4 にアップグレードする方法について説明します。

PHP 開発用に Visual Studio Code (VS Code) をセットアップする方法 PHP 開発用に Visual Studio Code (VS Code) をセットアップする方法 Dec 20, 2024 am 11:31 AM

Visual Studio Code (VS Code とも呼ばれる) は、すべての主要なオペレーティング システムで利用できる無料のソース コード エディター (統合開発環境 (IDE)) です。 多くのプログラミング言語の拡張機能の大規模なコレクションを備えた VS Code は、

PHPでHTML/XMLを解析および処理するにはどうすればよいですか? PHPでHTML/XMLを解析および処理するにはどうすればよいですか? Feb 07, 2025 am 11:57 AM

このチュートリアルでは、PHPを使用してXMLドキュメントを効率的に処理する方法を示しています。 XML(拡張可能なマークアップ言語)は、人間の読みやすさとマシン解析の両方に合わせて設計された多用途のテキストベースのマークアップ言語です。一般的にデータストレージに使用されます

JSON Web Tokens(JWT)とPHP APIでのユースケースを説明してください。 JSON Web Tokens(JWT)とPHP APIでのユースケースを説明してください。 Apr 05, 2025 am 12:04 AM

JWTは、JSONに基づくオープン標準であり、主にアイデンティティ認証と情報交換のために、当事者間で情報を安全に送信するために使用されます。 1。JWTは、ヘッダー、ペイロード、署名の3つの部分で構成されています。 2。JWTの実用的な原則には、JWTの生成、JWTの検証、ペイロードの解析という3つのステップが含まれます。 3. PHPでの認証にJWTを使用する場合、JWTを生成および検証でき、ユーザーの役割と許可情報を高度な使用に含めることができます。 4.一般的なエラーには、署名検証障害、トークンの有効期限、およびペイロードが大きくなります。デバッグスキルには、デバッグツールの使用とロギングが含まれます。 5.パフォーマンスの最適化とベストプラクティスには、適切な署名アルゴリズムの使用、有効期間を合理的に設定することが含まれます。

母音を文字列にカウントするPHPプログラム 母音を文字列にカウントするPHPプログラム Feb 07, 2025 pm 12:12 PM

文字列は、文字、数字、シンボルを含む一連の文字です。このチュートリアルでは、さまざまな方法を使用してPHPの特定の文字列内の母音の数を計算する方法を学びます。英語の母音は、a、e、i、o、u、そしてそれらは大文字または小文字である可能性があります。 母音とは何ですか? 母音は、特定の発音を表すアルファベットのある文字です。大文字と小文字など、英語には5つの母音があります。 a、e、i、o、u 例1 入力:string = "tutorialspoint" 出力:6 説明する 文字列「TutorialSpoint」の母音は、u、o、i、a、o、iです。合計で6元があります

PHPでの後期静的結合を説明します(静的::)。 PHPでの後期静的結合を説明します(静的::)。 Apr 03, 2025 am 12:04 AM

静的結合(静的::) PHPで後期静的結合(LSB)を実装し、クラスを定義するのではなく、静的コンテキストで呼び出しクラスを参照できるようにします。 1)解析プロセスは実行時に実行されます。2)継承関係のコールクラスを検索します。3)パフォーマンスオーバーヘッドをもたらす可能性があります。

PHPマジックメソッド(__construct、__destruct、__call、__get、__setなど)とは何ですか? PHPマジックメソッド(__construct、__destruct、__call、__get、__setなど)とは何ですか? Apr 03, 2025 am 12:03 AM

PHPの魔法の方法は何ですか? PHPの魔法の方法には次のものが含まれます。1。\ _ \ _コンストラクト、オブジェクトの初期化に使用されます。 2。\ _ \ _リソースのクリーンアップに使用される破壊。 3。\ _ \ _呼び出し、存在しないメソッド呼び出しを処理します。 4。\ _ \ _ get、dynamic属性アクセスを実装します。 5。\ _ \ _セット、動的属性設定を実装します。これらの方法は、特定の状況で自動的に呼び出され、コードの柔軟性と効率を向上させます。

一致式(PHP 8)とそれがスイッチとどのように異なるかを説明します。 一致式(PHP 8)とそれがスイッチとどのように異なるかを説明します。 Apr 06, 2025 am 12:03 AM

PHP8では、一致式は、式の値に基づいて異なる結果を返す新しい制御構造です。 1)Switchステートメントに似ていますが、実行ステートメントブロックの代わりに値を返します。 2)一致式の式は厳密に比較され、セキュリティが向上します。 3)スイッチステートメントの脱落の可能性を回避し、コードのシンプルさと読みやすさを向上させます。

See all articles