Need help with phpMobi?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

126 Stars 34 Forks Other 30 Commits 4 Opened issues


An experimental Mobipocket file creator in PHP

Services available


Need anything else?

Contributors list

# 112,686
Common ...
27 commits
# 596,080
2 commits

phpMobi file generator

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 = "...";
$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");


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.


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".


This code is released under the Apache license (version 2.0)

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.