A fluent interface for interacting with web sites, page content and URLs.
- PHP >= 8.5
- ext-curl
- ext-dom
- ext-filter
composer require myerscode/utilities-webuse Myerscode\Utilities\Web\Utility;
$web = new Utility('https://example.com');
// or use the static factory
$web = Utility::make('https://example.com');
// Get content from a URL
$content = $web->content()->content();
// Get a DOM crawler for the page
$dom = $web->content()->dom();
// Decode JSON responses
$data = $web->content()->json();
// Ping a host
$result = $web->ping()->ping();
$alive = $web->ping()->isAlive();
// Quick liveness check
$web->isAlive();
// Work with URLs
$uri = $web->url();
// Check response status
$response = $web->response()->check(\Myerscode\Utilities\Web\Data\ResponseFrom::CURL);
$response->isSuccessful(); // true for 2xxFetch and interact with web page content.
Ping hosts and check latency.
Parse, build and manipulate URLs.
All package exceptions extend Myerscode\Utilities\Web\Exceptions\WebUtilityException, which extends RuntimeException. This allows catching all package exceptions in one go:
use Myerscode\Utilities\Web\Exceptions\WebUtilityException;
try {
$content = $web->content()->content();
} catch (WebUtilityException $e) {
// Handle any package exception
}The MIT License (MIT). Please see License File for more information.