一个用于读取和操作 EPUB 文件内容和元数据的 PHP 库。

v1.0.1 2023-05-28 09:44 UTC

This package is auto-updated.

Last update: 2024-09-28 13:06:58 UTC


README

PHP 库,用于从 EPUB 文件中读取元数据、文档结构和纯文本内容。

来源

这个 PHP EPUB 库是基于 splitbrain/php-epub-meta 分支的。原始代码进行了相当大的修改,以适应我们的更传统 PHP 编码标准和 symfony 环境。附加功能包括读取 EPUB 的 TOC/spine 结构和从包含的 XML 文件中提取内容。

安装

使用 composer

composer require hans-thomas/epub

使用方法

<?php

// Open an EPUB file
$epub = new Epubli\Epub\Epub('/path/to/your/book.epub');
// and read some of its metadata
$title = $epub->getTitle();
$authors = $epub->getAuthors();
$desc = $epub->getDescription();

// Get the EPUB’s structural elements
$toc = $epub->getToc();
$spine = $epub->getSpine();

// Iterate over the EPUB structure
foreach ($spine as $spineItem) {
    // Get some text from the EPUB
    $chapterText = $spineItem->getContents();

    // Or find all navigation points pointing to that spine item
    $navPoints = $toc->findNavPointsForFile($spineItem->getHref());

    // Do something useful with the NavPoints.
    
    // At the end, don't forget to close the spine item
    $spineItem->close();
}