Skip to content

Commit

Permalink
release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nifrasismail committed Mar 18, 2019
0 parents commit 04268f9
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
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");
```

15 changes: 15 additions & 0 deletions composer.json
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": {}
}
25 changes: 25 additions & 0 deletions src/FileProcessor/Read.php
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;
}
}
24 changes: 24 additions & 0 deletions src/FileReadServiceProvider.php
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);
}
}

0 comments on commit 04268f9

Please sign in to comment.