P>刚学习PHP,由于网站空间不支持数据库,就写了这个类,正好来练习练习.
/*
This TextData Class txtTbl writen by ridge.jiang mostone@hotmail.com and finished in 2003.01.01
Your can copy and use it without agreedment,It's free. But you can't use it for busness using.
You are also wellcome to modify this code in your mind. Thank for your work and tell me.
This class is for small information database so like classmater databse,they are less than 300 recorders.
If your want store and opreat more than 300 recorders,It's recommandly to use SQL server.
Your may acess the Instance of this Class with bellow function,there recommandly Do NOT use
inner var and function,because that's unsafe.
create()
drop()
open()
close()
eof()
bof()
prev()
next()
first()
end()
fieldsCount()
getValue()
setValue()
display()
location()
recNO()
recCount()
del()
append()
*/
define ("tblPath",".\\");
define ("exten",".php");
define ("fileHead"," echo \"You are wellcome!\"?".">This file only for class txtTbl");
class txtTbl {
var $innerName=""; //数据库名称
var $innerCount; //数据库记录数目
var $innerFields; //数据库字段列表数组
var $inner_F_Count; //数据库字段数目
var $fullName; //完整的文件名
var $isModify = false; //当前记录是否被修改
var $fileModify = false; //数据库是否被修改
var $innerRecorders; //数据库记录数组
var $curLine; //当前记录号
var $curArray; //当前行数组
var $stringDel; //保存被删除记录
var $sprt1; //数据库记录间的分隔符
var $sprt2; //数据库字段间的分隔符
var $innerBof = true;
var $innerEof = false;
function create($tblName,$fields,$sprt1="\n",$sprt2=""){
if (empty($tblName)){
echo "The textDateBase file name not appoint.";
return false;
}
$fullName = tblPath.$tblName.exten;
if (file_exists($fullName)){
echo "The textDateBase file is already exist.";
return false;
}
if(empty($fields)){
echo "The fields list Array is invalid.";
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="\n",$sprt2=""){
if (empty($tblName)){
echo "The textDateBase file name not proveid.";
return false;
}
if (!empty($this->innerName)){
echo "Current file not closed,Please close it and try again.";
return false;
}
$fullName = tblPath.$tblName.exten;
if (!file_exists($fullName)){
echo "The textDateBase file not exist.";
return false;
}
$fp = fopen($fullName,"r");
if (!feof($fp)){
$readFromFile = fgets($fp);
}
if ($readFromFile!=fileHead."\n"){
fclose($fp);
echo "not a valid textDataBase file.(the head is invalid.)"."\n";
return false;
}
$readFromFile = "";
if (!feof($fp)) $readFromFile.= fgets($fp);
fclose($fp);
$readFromFile = trim($readFromFile);
if (empty($readFromFile)){
echo "not a valid textDataBase file.(can't find fields define.)";
return false;
}
$cont = fileHead."\n".$readFromFile;
$fp = fopen($fullName,"w");
fwrite($fp,$cont);
fclose($fp);
return true;
}
function open($tblName,$sprt1="\n",$sprt2=""){
if (empty($tblName)){
echo "The textDateBase file name not proveid.";
return false;
}
if (!empty($this->innerName)){
echo "Current file not closed,Please close it and try again.";
return false;
}
$this->fullName = tblPath.$tblName.exten;
if (!file_exists($this->fullName)){
echo "The textDateBase file not exist.";
return false;
}
$fp = fopen($this->fullName,"r");
if (!feof($fp)){
$readFromFile = fgets($fp);
}
if ($readFromFile!=fileHead."\n"){
fclose($fp);
echo "not a valid textDataBase file.(the head is invalid.)"."\n";
return false;
}
$readFromFile = "";
while (!feof($fp)) $readFromFile.= fgets($fp);
fclose($fp);
$readFromFile = trim($readFromFile);
if (empty($readFromFile)){
echo "not a valid textDataBase file.(can't find fields define.)";
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 modify
$isModify= false;
if ($this->isModify){
$this->saveModify();
$isModify= true;
}
if(isset($this->stringDel)){
$isModify= true;
$delNo= explode(",",$this->stringDel);
foreach($delNo as $no){
$no= (integer) $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->curLine = $this->innerCount;
$this->innerEof= true;
$this->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;
}
function recCount(){
return $this->innerCount;
}
function fieldsCount(){
if (empty($this->innerName)){
return false;
}else return $this->inner_F_Count;
}
function getValue($field){
if ($this->curLine==0||empty($this->innerName)){
echo "Can't read current record,maybe not in use or no record.";
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->innerName)){
echo "Can't read current record,maybe not in use or no record.";
return false;
}
$field= $this->chkField($field);
if ($field==-1){
return false;
}
$this->curArray[$field]= $value;
$this->modify= true;
}
function display($shownon=0,$sprt1="
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;$iinnerCount;$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 echo "del error:out over the rang.";
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;$iinnerFieldsCount;$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 "The Current Recorder fields count unequal to Table's.\n File will close.";
$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 "the key not appoint.";
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 "the field not appoint.";
return -1;
}
$vartype = gettype($field);
switch ($vartype) {
case "integer":
if ($field>=$this->innerFieldsCount){
echo "the field is large than fieldscount";
return -1;
}elseif($field echo "the field is less than 0";
return -1;
}
return $field;
case "string":
foreach ($this->innerFields as $k=>$v) if ($field==$v) return $k;
echo "the field name not found.";
return -1;
default:
echo "the field is invalid.";
return -1;
}
}
}
?>

PHPは、特にWeb開発の分野で、最新のプログラミングで強力で広く使用されているツールのままです。 1)PHPは使いやすく、データベースとシームレスに統合されており、多くの開発者にとって最初の選択肢です。 2)動的コンテンツ生成とオブジェクト指向プログラミングをサポートし、Webサイトを迅速に作成および保守するのに適しています。 3)PHPのパフォーマンスは、データベースクエリをキャッシュおよび最適化することで改善でき、その広範なコミュニティと豊富なエコシステムにより、今日のテクノロジースタックでは依然として重要になります。

PHPでは、弱い参照クラスを通じて弱い参照が実装され、ガベージコレクターがオブジェクトの回収を妨げません。弱い参照は、キャッシュシステムやイベントリスナーなどのシナリオに適しています。オブジェクトの生存を保証することはできず、ごみ収集が遅れる可能性があることに注意する必要があります。

\ _ \ _ Invokeメソッドを使用すると、オブジェクトを関数のように呼び出すことができます。 1。オブジェクトを呼び出すことができるように\ _ \ _呼び出しメソッドを定義します。 2。$ obj(...)構文を使用すると、PHPは\ _ \ _ Invokeメソッドを実行します。 3。ロギングや計算機、コードの柔軟性の向上、読みやすさなどのシナリオに適しています。

繊維はPhp8.1で導入され、同時処理機能が改善されました。 1)繊維は、コルーチンと同様の軽量の並行性モデルです。 2)開発者がタスクの実行フローを手動で制御できるようにし、I/O集約型タスクの処理に適しています。 3)繊維を使用すると、より効率的で応答性の高いコードを書き込むことができます。

PHPコミュニティは、開発者の成長を支援するための豊富なリソースとサポートを提供します。 1)リソースには、公式のドキュメント、チュートリアル、ブログ、LaravelやSymfonyなどのオープンソースプロジェクトが含まれます。 2)StackOverFlow、Reddit、およびSlackチャネルを通じてサポートを取得できます。 3)開発動向は、RFCに従うことで学ぶことができます。 4)コミュニティへの統合は、積極的な参加、コード共有への貢献、および学習共有への貢献を通じて達成できます。

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHPは、シンプルな構文と高い実行効率を備えたWeb開発に適しています。 2。Pythonは、簡潔な構文とリッチライブラリを備えたデータサイエンスと機械学習に適しています。

PHPは死にかけていませんが、常に適応して進化しています。 1)PHPは、1994年以来、新しいテクノロジーの傾向に適応するために複数のバージョンの反復を受けています。 2)現在、電子商取引、コンテンツ管理システム、その他の分野で広く使用されています。 3)PHP8は、パフォーマンスと近代化を改善するために、JITコンパイラおよびその他の機能を導入します。 4)Opcacheを使用してPSR-12標準に従って、パフォーマンスとコードの品質を最適化します。

PHPの将来は、新しいテクノロジーの傾向に適応し、革新的な機能を導入することで達成されます。1)クラウドコンピューティング、コンテナ化、マイクロサービスアーキテクチャに適応し、DockerとKubernetesをサポートします。 2)パフォーマンスとデータ処理の効率を改善するために、JITコンパイラと列挙タイプを導入します。 3)パフォーマンスを継続的に最適化し、ベストプラクティスを促進します。


ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

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

人気の記事

ホットツール

WebStorm Mac版
便利なJavaScript開発ツール

Dreamweaver Mac版
ビジュアル Web 開発ツール

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境
