From 62bb16f5815b2e330ca3c2c4c81d4a07d49df2dc Mon Sep 17 00:00:00 2001 From: stas Date: Mon, 1 Jul 2024 15:55:14 +0300 Subject: [PATCH] fix --- post.php | 3 --- post.txt | 4 +++- src/file_db_driver/FileDatabaseDriver.php | 20 +------------------- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/post.php b/post.php index 0274617..2965b2f 100644 --- a/post.php +++ b/post.php @@ -10,9 +10,6 @@ require_once "vendor/autoload.php"; ini_set("display_errors", true); error_reporting(-1); -//$fileName = "Information.txt"; -//$fileModeOpen = "a"; - $post = new PostModel(); $post->load($_REQUEST); $post->save(); diff --git a/post.txt b/post.txt index d070af1..c634f3f 100644 --- a/post.txt +++ b/post.txt @@ -1,4 +1,6 @@ -autoincrement=id;last_id=2;table_name=post +autoincrement=id;last_id=4;table_name=post id;author;post 1;Stas;Hello, world!!! 2;Stas;Hello, world!!! +3;Stas;Hello,
My php
World!!! +4;Stas;Hello,
My php
World!!! diff --git a/src/file_db_driver/FileDatabaseDriver.php b/src/file_db_driver/FileDatabaseDriver.php index c2b60fe..85346ce 100644 --- a/src/file_db_driver/FileDatabaseDriver.php +++ b/src/file_db_driver/FileDatabaseDriver.php @@ -151,24 +151,6 @@ class FileDatabaseDriver fclose($this->file); } -// public function updateServiceInfo(string $string): void -// { -// $id = $this->serviceInfo['last_id']; -// $this->serviceInfo['last_id'] = ++$id; -// foreach ($this->serviceInfo as $key => $value) { -// $arr[] = $key . '=' . $value; -// } -// $fileArr = file($this->filePath); -// if (isset($arr)) { -// $serviceStr = implode(';', $arr) . "\n"; -// } -// $fileArr[0] = $serviceStr; -// file_put_contents($this->filePath, $fileArr); -// -// $str = $id . ';' . $string; -// $this->save($str); -// } - public function save(string $string): void { $this->serviceInfo['last_id']++; @@ -182,7 +164,7 @@ class FileDatabaseDriver $fileArr[0] = $serviceStr; file_put_contents($this->filePath, $fileArr); - $str = $this->serviceInfo['last_id'] . ';' . $string . "\n"; + $str = $this->serviceInfo['last_id'] . ';' . str_replace("\r\n", "
", $string) . "\n"; fwrite($this->file, $str); $this->close();