-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 04268f9
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#Read Text Files - FileRead Packagist | ||
|
||
This package helps to convert any text file to array. So it is makes life easier to read | ||
the file in array format. | ||
|
||
#Usage | ||
|
||
where ever you need to read the file just adding the path of the text file as follow. | ||
|
||
usually people put their files on storage directory of laravel | ||
```php | ||
use Nertlab\FileRead\FileProcessor\Read; | ||
|
||
$contents = (new Read())->readFile(storage_path('app/myFile.txt')); | ||
``` | ||
|
||
By default we are set delimiters of line are `\n` and word delimiter as`\t` | ||
|
||
you can by pass this as follow | ||
```php | ||
use Nertlab\FileRead\FileProcessor\Read; | ||
|
||
$contents = (new Read())->readFile(storage_path('app/myFile.txt'), "\n", "\t"); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "nertlab/file-read", | ||
"description": "Reading Files", | ||
"version": "1.0.0", | ||
"type": "project", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "nifrasismail", | ||
"email": "nifrasismail@gmail.com" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* Read File Package | ||
* | ||
* @author Nifras Ismail <nifrasismail@gmail.com> | ||
* @copyright Copyright © 2019 Nertlab. | ||
* @license MIT | ||
*/ | ||
namespace Nertlab\FileRead\FileProcessor; | ||
|
||
use Illuminate\Support\Facades\File; | ||
|
||
class Read | ||
{ | ||
public function readFile($path, $line_delimiter="\n", $word_delimiter="\t") | ||
{ | ||
$contents = File::get($path); | ||
$lines = explode($line_delimiter,$contents); | ||
$array = array(); | ||
foreach ($lines as $line){ | ||
array_push($array,explode($word_delimiter,$line)); | ||
} | ||
return $array; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* Read File Package | ||
* | ||
* @author Nifras Ismail <nifrasismail@gmail.com> | ||
* @copyright Copyright © 2019 Nertlab. | ||
* @license MIT | ||
*/ | ||
namespace Nertlab\FileRead; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class FileReadServiceProvider extends ServiceProvider | ||
{ | ||
public function boot() | ||
{ | ||
|
||
} | ||
|
||
public function register() | ||
{ | ||
$this->app->register(FileReadServiceProvider::class); | ||
} | ||
} |