collecthor / spss
SPSS is a php-based implementation of IBM SPSS Statistics Standard
v3.1.1
2021-11-19 08:26 UTC
Requires
- php: >=8.0
- ext-bcmath: *
- ext-mbstring: *
Requires (Dev)
- doctrine/instantiator: 1.0.5
- phing/phing: ^2
- phpdocumentor/reflection-docblock: 3.0.2
- phpunit/phpunit: ^4.8
- squizlabs/php_codesniffer: ^3
README
A PHP library for reading and writing SPSS / PSPP .sav data files. This library was forked from tiamo/spss since the original is not seeing a lot of activity.
VERSION 2.1.0 (CHANGELOG)
Plans
The plan is, in time, to fully rewrite this library to allow for streaming large datasets.
Requirements
- PHP 7.3.0 and up (this fork will not support PHP versions that do not have active support)
- mbstring extension
- bcmath extension
Installation
The preferred way to install this extension is through composer.
Either run
composer require collecthor/spss
or add
"tiamo/spss": "*"
to the require section of your composer.json
file
or download from here.
Usage
Reader example:
// Initialize reader $reader = \collecthor\spss\Reader::fromFile('path/to/file.sav'); // Read header data $reader->readHeader(); // var_dump($reader->header); // Read full data $reader->read(); // var_dump($reader->variables); // var_dump($reader->valueLabels); // var_dump($reader->documents); // var_dump($reader->data);
or
$reader = \collecthor\spss\Reader::fromString(file_get_contents('path/to/file.sav'))->read();
Writer example:
$writer = new \collecthor\spss\Writer([ 'header' => [ 'prodName' => '@(#) SPSS DATA FILE test', 'layoutCode' => 2, 'compression' => 1, 'weightIndex' => 0, 'bias' => 100, 'creationDate' => '01 Feb 01', 'creationTime' => '01:01:01', ], 'variables' => [ [ 'name' => 'VAR1', # For UTF-8, 64 / 3 = 21, mb_substr($var1, 0, 21); 'width' => 0, 'decimals' => 0, 'format' => 5, 'columns' => 50, 'align' => 1, 'measure' => 1, 'data' => [ 1, 2, 3 ], ], ... ] ]);
Changelog
Please have a look in CHANGELOG
License
Licensed under the MIT license.