PHP code example of ixnode / php-container

1. Go to this page and download the library: Download ixnode/php-container library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ixnode / php-container example snippets


use Ixnode\PhpContainer\File;

$exists = (new File('path-to-file'))->exist();

true || false

$fileSize = (new File('path-to-file'))->getFileSize();

1523943

$fileSizeHuman = (new File('path-to-file'))->getFileSizeHuman();

1.45 MB

$content = (new File('path-to-file'))->getContentAsText();

line 1
line 2
line 3
...

$content = (new File('path-to-json-file'))->getJson()->getJsonStringFormatted();

{
    "data": "Content of file 'path-to-json-file'."
}

use Ixnode\PhpContainer\Json;

$json = (new Json(['data' => 'json']))->getJsonStringFormatted();

$array = (new Json('{"data": "json"}'))->getArray();

[
    'data' => 'json',
]

$array = (new Json(new File('path-to-json-file')))->getArray();

[
    "data" => "Content of file 'path-to-json-file'.",
]

$array = (new Json('[{"key1": 111, "key2": "222"},{"key1": 333, "key2": "444"}]'))->buildArray(
    [
        /* path []['key1'] as area1 */
        'area1' => [['key1']],
        /* path []['key2'] as area2 */
        'area2' => [['key2']],
    ]
);

[
    'area1' => [111, 333],
    'area2' => ['222', '444'],
]

use Ixnode\PhpContainer\Csv;

$array = (new Csv(new File('path-to-csv-file')))->getArray();

[
    [
        'headerLine1Cell1' => 'valueLine2Cell1',
        'headerLine1Cell2' => 'valueLine2Cell2',
    ],    
    [
        'headerLine1Cell1' => 'valueLine3Cell1',
        'headerLine1Cell2' => 'valueLine3Cell2',
    ],
    ...
]

use Ixnode\PhpContainer\Curl;

$text = (new Curl('URL')->getContentAsText();

use Ixnode\PhpContainer\Image;

$imageWidth = (new Image(new File('path-to-json-file')))->getWidth();

$imageString = (new Image(new File('path-to-json-file')))->getImageString(1000, Image::FORMAT_JPG, 85);
bash
composer 
bash
vendor/bin/php-container -V
bash
php-container 0.1.0 (12-19-2022 01:17:26) - Björn Hempel <[email protected]>
text
"headerLine1Cell1";"headerLine1Cell2"
"valueLine2Cell1";"valueLine2Cell2"
"valueLine3Cell1";"valueLine3Cell2"
bash
git clone [email protected]:ixnode/php-container.git && cd php-container