Skip to content
/ spss Public
forked from tiamo/spss

SPSS, PSPP php implementation (read/write .sav files)

License

Notifications You must be signed in to change notification settings

meletis/spss

 
 

Repository files navigation

SPSS / PSPP

A PHP library for reading and writing SPSS / PSPP .sav data files.

VERSION 2.1.0 (CHANGELOG)

Build Status

Requirements

  • PHP 5.5.0 and up
  • mbstring extension
  • bcmath extension

Installation

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.

Usage

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
                ],
        ],
        ...
    ]
]);

Changelog

Please have a look in CHANGELOG

License

Licensed under the MIT license.

About

SPSS, PSPP php implementation (read/write .sav files)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 99.9%
  • Shell 0.1%