$longUrl, ]; // Add custom alias if provided if ($customAlias) { $data['alias'] = $customAlias; } $options = [ 'http' => [ 'header' => [ 'Authorization: Bearer ' . $apiToken, 'Content-Type: application/json', ], 'method' => 'POST', 'content' => json_encode($data), ], ]; $context = stream_context_create($options); $result = file_get_contents($apiUrl, false, $context); if ($result === FALSE) { return "Error: Failed to shorten URL"; } $response = json_decode($result, true); if (isset($response['data']['tiny_url'])) { return $response['data']['tiny_url']; } else { return "Error: " . ($response['errors'][0] ?? 'Unknown error'); } } // Your API token $apiToken = 'UuX9eFDFXsxDPDeJjT8FrhOFyij7aer6saFWffr6Chnpagg0ZNngzolkrpGq'; // URL to shorten $longUrl = 'https://www.example.com/very/long/url/that/needs/to/be/shortened'; // Custom name for your URL (only letters, numbers, underscores, or hyphens) $customName = 'lordofcoding'; // Shorten the URL with custom name $shortUrl = shortenUrlWithTinyUrl($longUrl, $apiToken, $customName); // Output the result echo "Long URL: " . $longUrl . "\n"; echo "Short URL: " . $shortUrl . "\n"; ?>