How to convert website URL page to text TXT in PHP

Today we are going to be looking at how to extract all of the basic text from a web page and exporting it as a TXT file. This has never been easier for PHP users, with the entire process taking no time at all. Here’s how.

Using this command for Composer, we can install our client.

composer require cloudmersive/cloudmersive_document_convert_api_client

With the client installed, we are free to call our function, which will in turn perform the website conversion for us.

<?phprequire_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');$apiInstance = new Swagger\Client\Api\ConvertWebApi(// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.// This is optional, `GuzzleHttp\Client` will be used as GuzzleHttp\Client(),$config);$input = new \Swagger\Client\Model\UrlToTextRequest(); // \Swagger\Client\Model\UrlToTextRequest | HTML to Text request parameterstry {$result = $apiInstance->convertWebUrlToTxt($input);print_r($result);} catch (Exception $e) {echo 'Exception when calling ConvertWebApi->convertWebUrlToTxt: ', $e->getMessage(), PHP_EOL;}?>

Now all that’s needed is to input our URL. The API will do the rest.

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