donatj/webarchive

Library for writing Apple Safari's '.Webarchive' format (binary plist).

v1.0.1 2025-09-10 08:16 UTC

This package is auto-updated.

Last update: 2025-09-10 08:18:29 UTC


README

Latest Stable Version Total Downloads License ci.yml

A library for writing Apple Safari 'webarchive' files

Requirements

  • rodneyrehm/plist: 2.*
  • php: >=5.3

Installing

Install the latest version with:

composer require 'donatj/webarchive'

Examples

<?php

require_once __DIR__ . '/../vendor/autoload.php';

$archive = new \donatj\Webarchive();

// Main HTML document (entry point)
$html = "<html><head><title>Example</title><link rel=\"stylesheet\" href=\"style.css\"></head><body><h1>Hello Webarchive</h1></body></html>";
$archive->addMainResource($html, 'https://example.test/index.html', 'text/html', 'UTF-8');

// A simple CSS subresource referenced by the HTML page
$css = "body{font-family:sans-serif;background:#fafafa;color:#333;} h1{color:#0066cc;}";
$archive->addSubResource($css, 'https://example.test/style.css', 'text/css');

// Save the webarchive (binary plist) to a file
$outFile = __DIR__ . '/basic.webarchive';
$archive->save($outFile);

echo "Wrote webarchive: " . $outFile . "\n";

Documentation

Class: donatj\Webarchive

Method: Webarchive->__construct

function __construct()

Webarchive constructor

Method: Webarchive->addMainResource

function addMainResource($content [, $url = null [, $mime = 'text/html' [, $charset = 'UTF-8' [, $headers = null]]]])

Adds the Primary "MainResource" - which is the entry point into the web archive,
usually an HTML document.

Parameters:
  • string $content
  • string | null $url
  • string $mime
  • string | null $charset
  • string | null $headers

Method: Webarchive->addSubResource

function addSubResource($content, $url [, $mime = 'text/html' [, $charset = null [, $headers = null]]])

Adds a secondary resource. Images, JavaScript, XML, JSON, etc.

Resources to accompany the primary document.

Parameters:
  • string $content
  • string | null $url
  • string $mime
  • string | null $charset
  • string | null $headers

Method: Webarchive->save

function save($filename)

Save to a file

Parameters:
  • mixed $filename - string

Method: Webarchive->output

function output()

Output to php://output