aneeskhan47/php-howlongtobeat-api

A PHP API wrapper for HowLongToBeat.com

v1.0.1 2025-02-06 13:14 UTC

This package is auto-updated.

Last update: 2025-02-06 13:25:10 UTC


README

PHP HowLongToBeat API

GitHub Workflow Status (master) Total Downloads Latest Version License

A simple PHP API to read data from HowLongToBeat.com.

It is inspired by ScrappyCocco - HowLongToBeat-PythonAPI Python API.

⚡️ Installation

Requires PHP 7.4 or higher

composer require aneeskhan47/php-howlongtobeat-api

🚀 Usage

Search for games by title

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.

Search for a single game by its ID

$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";

🔒 Security

If you discover any security-related issues, please email kingkhan2388@gmail.com instead of using the issue tracker.

🙌 Credits

📜 License

The MIT License (MIT). Please see License File for more information.