Skip to content

aneeskhan47/php-howlongtobeat-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 [email protected] instead of using the issue tracker.


🙌 Credits


📜 License

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