A simple PHP API to read data from HowLongToBeat.com.
It is inspired by ScrappyCocco - HowLongToBeat-PythonAPI Python API.
Requires PHP 7.4 or higher
composer require aneeskhan47/php-howlongtobeat-api
by default, it will return 25 results per page and the first page.
require 'vendor/autoload.php';
use AneesKhan47\HowLongToBeat\HowLongToBeat;
$hltb = new HowLongToBeat();
try {
$results = $hltb->searchByTitle("The Last of Us");
foreach ($results->games as $game) {
echo "Game: " . $game->name . "\n";
echo "Image: " . $game->image_url . "\n";
echo "Main Story: " . $game->main_story_time . "\n";
echo "Main + Extra: " . $game->main_extra_time . "\n";
echo "Completionist: " . $game->completionist_time . "\n";
echo "------------------------\n";
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
You can also specify the number of results per page. for example, to get second page with 10 results per page, you can do this:
$results = $hltb->searchByTitle("The Last of Us", 2, 10);
Note: The maximum number of results per allowed is 25. This is by HowLongToBeat.com limitation.
$game = $hltb->searchById(26286);
echo "Game: " . $game->name . "\n";
echo "Image: " . $game->image_url . "\n";
echo "Main Story: " . $game->main_story_time . "\n";
echo "Main + Extra: " . $game->main_extra_time . "\n";
echo "Completionist: " . $game->completionist_time . "\n";
echo "------------------------\n";
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.