How to Validate a URL (Fully) in PHP

Cloudmersive
1 min readApr 24, 2023

--

If you’re looking for an easy way to check the validity of URL syntax, domain and endpoint, look no further: using the below code, you can quickly validate all of the above information in a single API request — and you can do it for free (up to 800 API calls per month) with a free-tier Cloudmersive API key.

We can start by installing the client SDK. Let’s run the following command:

composer require cloudmersive/cloudmersive_validate_api_client

Now let’s copy the below PHP code examples to structure our API calls:

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');



$apiInstance = new Swagger\Client\Api\DomainApi(


new GuzzleHttp\Client(),
$config
);
$request = new \Swagger\Client\Model\ValidateUrlRequestFull(); // \Swagger\Client\Model\ValidateUrlRequestFull | Input URL request

try {
$result = $apiInstance->domainUrlFull($request);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling DomainApi->domainUrlFull: ', $e->getMessage(), PHP_EOL;
}
?>

That’s all there is to it!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet