Get epub metadata (with php)

I found something to get epub metadata with php on github, but with a very complex code.
It would be possible to do that with a simpler code?

If this is not possible, an alternative could be get something from the name of the epub file, such as [en], or [de], or [fr]: having epub files named myname [en].epub, in the webpage I should get the (English) after the name of the file.
I think this should be easier…


But here there is an interesting project.

Could help me to try that method?
I have installed php-ebook, as in my previous post.
However my knowledge of php is quite limited.
I tried with this code

use Kiwilan\Ebook\Ebook;

$ebook = Ebook::read('../../web/etexts/filosofi/antichi/Aristotele - la Fisica.epub');
$ebooktitle="$ebook->getTitle()"; // string
$ebookautore="$ebook->getAuthors()"; // BookAuthor[] (`name`: string, `role`: string)
echo "<p>$ebookautore, <i>$ebooktitle</i></p>";

But I don’t get any output…


I had a look also for javascript solutions: there are several, but I think that it’s too complicated.
Therefore I guess that the best way could be a php script to add some values from some others in filename, as I said before (#4).

You cant put object references inside of strings without indicating to PHP that it’s a full object reference. That said, you dont need to store those variables as strings.
$ebooktitle= $ebook->getTitle();

Note that the authors is an array, so you will need to either print_r it or otherwise handle the array reference, as array to string conversion is not implicit.

1 Like

Thank you, @m_hutley, but there are too things that I don’t understand (i.g. what mean
«indicating to PHP that it’s a full object reference»).
Therefore I would prefer to do the alternative (at my post #4), if possible.

some methods of preg_match, explode, or str_pos will be able to get you there from the filename, if the filename can be guaranteed to have your information in it.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.