PHP code example of wallabag / php-mobi

1. Go to this page and download the library: Download wallabag/php-mobi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wallabag / php-mobi example snippets


// 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');

$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');