SPSS is a php-based implementation of IBM SPSS Statistics Standard

Maintainers

Details

github.com/collecthor/spss

Source

Installs: 16 288

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 37

v3.1.1 2021-11-19 08:26 UTC

This package is auto-updated.

Last update: 2024-10-19 14:33:30 UTC


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)

Build Status Latest Stable Version Total Downloads Latest Unstable Version License Code Coverage Scrutinizer Code Quality

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.