저자: A. Grandt (php@grandt.com)
예제 #1
0
use PHPePub\Core\EPubChapterSplitter;
use PHPePub\Core\Structure\OPF\DublinCore;
use PHPePub\Core\Logger;
use PHPePub\Core\Structure\OPF\MetaValue;
use PHPZip\Zip\File\Zip;
error_reporting(E_ALL | E_STRICT);
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 1);
// Example.
// Create a test book for download.
// ePub uses XHTML 1.1, preferably strict.
$content_start = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n" . "    \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" . "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" . "<head>" . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" . "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\" />\n" . "<title>Test Book</title>\n" . "</head>\n" . "<body>\n";
$bookEnd = "</body>\n</html>\n";
// setting timezone for time functions used for logging to work properly
date_default_timezone_set('Europe/Berlin');
$log = new Logger("Example", TRUE);
$fileDir = './PHPePub';
// Default is EPub::BOOK_VERSION_EPUB2
$book = new EPub();
$log->logLine("new EPub()");
$log->logLine("EPub class version.: " . EPub::VERSION);
$log->logLine("Zip version........: " . Zip::VERSION);
$log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
$log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());
// Title and Identifier are mandatory!
$book->setTitle("Test book");
$book->setIdentifier("http://JohnJaneDoePublications.com/books/TestBook.html", EPub::IDENTIFIER_URI);
// Could also be the ISBN number, preferred for published books, or a UUID.
$book->setLanguage("en");
// Not needed, but included for the example, Language is mandatory, but EPub defaults to "en". Use RFC3066 Language codes, such as "en", "da", "fr" etc.
$book->setDescription("This is a brief description\nA test ePub book as an example of building a book in PHP");
예제 #2
0
include 'vendor/autoload.php';
use PHPePub\Core\EPub;
use PHPePub\Core\Structure\OPF\DublinCore;
use PHPePub\Core\Logger;
use PHPZip\Zip\File\Zip;
error_reporting(E_ALL | E_STRICT);
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 1);
// Example.
// Create a test book for download.
// ePub 3 uses a variant of HTML5 called XHTML5
$content_start = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n" . "<head>" . "<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n" . "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\" />\n" . "<title>Test Book</title>\n" . "</head>\n" . "<body>\n";
$bookEnd = "</body>\n</html>\n";
// setting timezone for time functions used for logging to work properly
date_default_timezone_set('Europe/Berlin');
$log = new Logger("Example", TRUE);
$fileDir = './PHPePub';
// ePub 3 is not fully implemented. but aspects of it is, in order to help implementers.
// ePub 3 uses HTML5, formatted strictly as if it was XHTML but still using just the HTML5 doctype (aka XHTML5)
$book = new EPub(EPub::BOOK_VERSION_EPUB3, "en", EPub::DIRECTION_LEFT_TO_RIGHT);
// Default is ePub 2
$log->logLine("new EPub()");
$log->logLine("EPub class version.: " . EPub::VERSION);
$log->logLine("Zip version........: " . Zip::VERSION);
$log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
$log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());
// Title and Identifier are mandatory!
$book->setTitle("ePub 3 Test book");
$book->setIdentifier("http://JohnJaneDoePublications.com/books/TestBookEPub3.html", EPub::IDENTIFIER_URI);
// Could also be the ISBN number, preferred for published books, or a UUID.
$book->setLanguage("en");