2
2
[ ![ Codacy Badge] ( https://app.codacy.com/project/badge/Grade/c6450a9c0f99488e93b34911f1adfb2e )] ( https://app.codacy.com/gh/rcsofttech85/php-file-helper/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade )
3
3
[ ![ Codacy Badge] ( https://app.codacy.com/project/badge/Coverage/c6450a9c0f99488e93b34911f1adfb2e )] ( https://app.codacy.com/gh/rcsofttech85/php-file-helper/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage )
4
4
5
-
6
-
7
-
8
-
9
5
** A simple php file helper** ✨
10
6
11
-
12
-
13
7
==========================================
14
8
15
9
** Installation**
@@ -19,36 +13,39 @@ composer require rcsofttech85/file-handler
19
13
20
14
```
21
15
22
-
23
16
** search by a keyword in file**
24
17
25
18
```
26
- $fileHandler = new FileHandler();
19
+ $temp = new TempFileHandler();
20
+ $csv = new CsvFileHandler($temp);
21
+
22
+ $findByKeyword = $csv->searchInCsvFile("movies.csv","Twilight","Film");
27
23
28
- $fileHandler->open(filename: 'movie.csv',mode:'r')->searchInCsvFile(keyword: 'Twilight',column:'Film');
29
24
30
25
```
31
26
32
27
** search by a keyword in file and return array**
33
28
34
29
```
35
- $fileHandler = new FileHandler();
30
+ $temp = new TempFileHandler();
31
+ $csv = new CsvFileHandler($temp);
36
32
37
- $fileHandler->open(filename: 'movie. csv',mode:'r') ->searchInCsvFile(keyword: 'Zack and Miri Make a Porno',column:' Film', format: FileHandler::ARRAY_FORMAT);
33
+ $findByKeyword = $ csv->searchInCsvFile("movies.csv","Twilight"," Film", FileHandler::ARRAY_FORMAT);
38
34
39
35
// output
40
36
41
37
[
42
- ' Film' => 'Zack and Miri Make a Porno',
43
- ' Genre' => ' Romance',
44
- ' Lead Studio' => 'The Weinstein Company',
45
- ' Audience score %' => '70',
46
- ' Profitability' => '1.747541667',
47
- ' Rotten Tomatoes %' => '64',
48
- ' Worldwide Gross' => '$41.94 ',
49
- ' Year' => ' 2008'
38
+ [ Film] => Twilight
39
+ [ Genre] => Romance
40
+ [ Lead Studio] => Summit
41
+ [ Audience score %] => 82
42
+ [ Profitability] => 10.18002703
43
+ [ Rotten Tomatoes %] => 49
44
+ [ Worldwide Gross] => $376.66
45
+ [ Year] => 2008
50
46
51
- ];
47
+
48
+ ];
52
49
```
53
50
54
51
** Write multiple file simultaneously:**
@@ -69,10 +66,11 @@ $fileHandler->close();
69
66
** converting file to an array**
70
67
71
68
```
72
- $fileHandler = new FileHandler();
73
69
74
- $data = $fileHandler->open(filename: 'movie.csv',mode:'r')->toArray();
70
+ $temp = new TempFileHandler();
71
+ $csv = new CsvFileHandler($temp);
75
72
73
+ $findByKeyword = $csv->toArray("movies.csv");
76
74
// output
77
75
$data[0] = [
78
76
'Film' => 'Zack and Miri Make a Porno',
@@ -88,11 +86,36 @@ $data[0] = [
88
86
89
87
```
90
88
89
+ ** Find and replace in csv file**
90
+
91
+ ```
92
+
93
+ $temp = new TempFileHandler();
94
+ $csv = new CsvFileHandler($temp);
95
+
96
+ $findByKeyword = $csv->findAndReplaceInCsv("movies.csv","Twilight","Inception");
97
+
98
+ ```
99
+
100
+ ** Find and replace a specific keyword in a particular column of a CSV file**
101
+
102
+ ```
103
+
104
+ $temp = new TempFileHandler();
105
+ $csv = new CsvFileHandler($temp);
106
+
107
+ $findByKeyword = $csv->findAndReplaceInCsv("movies.csv","Inception","Twilight",column: "Film");
108
+
109
+ ```
110
+
91
111
** converting file to a json format**
92
112
93
113
```
94
- $fileHandler = new FileHandler();
95
- $this->fileHandler->open(filename: 'movie.csv')->toJson();
114
+
115
+ $temp = new TempFileHandler();
116
+ $csv = new CsvFileHandler($temp);
117
+
118
+ $findByKeyword = $csv->toJson("movies.csv");
96
119
97
120
//output
98
121
[{"Film":"Zack and Miri Make a Porno","Genre":"Romance","Lead Studio":"The Weinstein Company","Audience score %":"70","Profitability":"1.747541667","Rotten Tomatoes %":"64","Worldwide Gross":"$41.94 ","Year":"2008"},{"Film":"Youth in Revolt","Genre":"Comedy","Lead Studio":"The Weinstein Company","Audience score %":"52","Profitability":"1.09","Rotten Tomatoes %":"68","Worldwide Gross":"$19.62 ","Year":"2010"},{"Film":"Twilight","Genre":"Romance","Lead Studio":"Independent","Audience score %":"68","Profitability":"6.383363636","Rotten Tomatoes %":"26","Worldwide Gross":"$702.17 ","Year":"2011"}]
@@ -160,7 +183,7 @@ vendor/bin/file-diff oldFile newFile
160
183
161
184
```
162
185
163
- ** File Integrity**
186
+ ** File Integrity check **
164
187
165
188
```
166
189
$fileHasher = new FileHashChecker();
0 commit comments