A PHP library for reading and writing SPSS / PSPP .sav data files.
VERSION 2.1.0 (CHANGELOG)
- PHP 5.5.0 and up
- mbstring extension
- bcmath extension
The preferred way to install this extension is through composer.
Either run
composer require tiamo/spss
or add
"tiamo/spss": "*"
to the require section of your composer.json
file
or download from here.
Reader example:
// Initialize reader
$reader = \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 = \SPSS\Reader::fromString(file_get_contents('path/to/file.sav'))->read();
Writer example:
$writer = new \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
],
],
...
]
]);
Please have a look in CHANGELOG
Licensed under the MIT license.