A PHP library for reading and writing SPSS / PSPP .sav data files.
VERSION 4.* (see upgrade section for details)
Fork of tiamo/spss. Mostly same code base. Introdusing a more complete test enviroment which now exists over there. So, one day i switch back to it.
Table of contents
PHP 8.0 and up.
- php-cli
- php-mdstring
- php-bcmath
The preferred way to install this extension is through composer
Either run
composer require flobee/spss
to the require section of your composer.json
file see here
or download from here.
In folder examples/ you will find some more examples.
Reader example:
$reader = \SPSS\Sav\Reader::fromFile('path/to/file.sav')->read();
or
$reader = \SPSS\Sav\Reader::fromString(file_get_contents('path/to/file.sav'))->read();
Writer example:
$writer = new \SPSS\Sav\Writer([
'header' => [
'prodName' => '@(#) SPSS DATA FILE test',
'layoutCode' => 2,
'compression' => 1,
'weightIndex' => 0,
'bias' => 100,
'creationDate' => '13 Feb 89',
'creationTime' => '23:58:59',
],
'variables' => [
[
'name' => 'VAR1',
'width' => 0,
'decimals' => 0
'format' => 5,
'columns' => 50,
'align' => 1,
'measure' => 1,
'data' => [
1, 2, 3
],
],
...
]
]);
...
git clone https://github.com/flobee/spss.git
cd spss/
git submodule init # once
git submodule update --recursive # upgrading (after a `git pull`)
Initialy or for upgrades to get development dependencies:
composer install
For more dev-tools you may install phpstan/phpstan composer require -dev phpstan/phpstan
which shows a lot of stucture problems of the application and it should getting more
attention (beginning with level=1).
git pull
git submodule update
composer install
VERSION 4:
Improved additions for CI systems (e.g: jenkins) where `phing` is the
prefered build tool. `composer` the prefered package manager.
# shows you the options
./phing -l
# executes the tests
./phing test
# executes the tests and create the code coverage
./phing coverage
# run all tasks (CS checks, coverage, tests, sca...)
./phing all
...
cd tests
sh ./runTests.sh
# have a look at ../docs/CodeCoverage (use a browser after execution)
sh ./runTestsCoverageCreate.sh
# playground:
php readerDemo.php | less
# or to update tmp file to check for changes:
php readerDemo.php > data/pspp.sav.printr.txt
Update your composer.json
{
...
"require": {
"flobee/spss": "3.*",
},
...
}
Next:
composer update flobee/spss
Dependency Errors?
If you get dependency errors, you may upgrade other spss dependencies too. If so try the following:
composer update flobee/spss --with-dependencies
Please have a look in docs/CHANGELOG.md
Please have a look in License text