wallabag/php-mobi
最新稳定版本:1.1.1
Composer 安装命令:
composer require wallabag/php-mobi
包简介
A Mobipocket file (.mobi) creator in PHP.
README 文档
README
phpMobi is a php script that can generate .mobi files from valid html files. While this was meant as an experiment, this tool works quite well and can be used to generate mobipocket files from most news articles.
IMPORTANT: Do NOT use this on a public web server: most of it was coded in a weekend, with no testing and no special attention to security. Also, as no official documentation for the MOBI file format is available, there will be some bugs/problems in the generated files, but it works for relatively simple documents on the Kindle previewer and the Kindle 3.
MobiPocket is an eBook format created by Mobipocket SA. This tool also uses a php readability port made by Keyvan Minoukadeh.
Code sample
See index.php for an example of using this program.
Sending an online article as a download:
// Create the MOBI object $mobi = new MOBI(); // Set the content provider $content = new OnlineArticle('URL'); $mobi->setContentProvider($content); // Get title and make it a 12 character long url-safe filename $title = $mobi->getTitle(); if ($title === false) { $title = 'file'; } $title = urlencode(str_replace(' ', '_', strtolower(substr($title, 0, 12)))); // Send the mobi file as download $mobi->download($title.'.mobi');
Using a previously generated/downloaded html file (will not download any images!):
$data = '<html>...</html>'; $options = array( 'title' => 'Local document', 'author' => 'Author name', 'subject' => 'Subject' ); // Create the MOBI object $mobi = new MOBI(); // Set the data $mobi->setData($data); $mobi->setOptions($options); // Save the mobi file locally $mobi->save($options['title'].'.mobi');
Implementation
This code was implemented while reverse-engineering the MobiPocket format. Therefore this code absolutely isn't optimized for speed, but rather for easy changes, as getting it to produce valid files was quite fiddly.
Features
Modular content provider system: Adding a new data source can be done by extending the ContentProvider class. See the OnlineArticle class for a simple but complete implementation of such a system.
Image support: By default, the online article downloader (and any other content provider that supports images) will download images and integrate them into the mobi file.
Partial UTF-8 support: In practice UTF-8 just works, but there are some unhandled corner cases (see missing features).
Missing Features
Compression: This won't be implemented (or if it is, only to serve as a reference of the format).
Different eBook types: MobiPocket supports other formats/layouts, such as newspaper-like formats. At the moment only the book layout has been implemented.
Full UTF-8 support: UTF-8 should work most of the time (it worked every time I tested it), but there might be some problems when the character is split over two "records".
License
This code is released under the Apache license (version 2.0)
wallabag/php-mobi 适用场景与选型建议
wallabag/php-mobi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 195.01k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 wallabag/php-mobi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wallabag/php-mobi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 195.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-01-04