Conversion Tools API PHP Client
Conversion Tools is an online service that offers a fast and easy way to convert documents between different formats, like XML, Excel, PDF, Word, Text, CSV and others.
This client allows to integrate the conversion of the files into PHP applications.
To convert the files PHP Client uses the public Conversion Tools REST API.
composer require conversiontools/conversiontools-php
or without composer:
require_once('conversiontools-php/src/autoload.php');
To use REST API - get API Token from the Profile page at https://conversiontools.io/profile.
See example convert-file.php
in the ./examples/
folder.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use \ConversionTools\ConversionClient;
// put token here from your Profile page at https://conversiontools.io/profile
$token = '';
$fileOrUrlInput = 'test.xml';
$fileOutput = 'test.csv';
$options = ['delimiter' => 'tabulation'];
$client = new ConversionClient($token);
try {
$client->convert('convert.xml_to_csv', $fileOrUrlInput, $fileOutput, $options);
} catch (Exception $e) {
print 'Exception: ' . $e->getMessage() . "\n";
}
See example convert-url.php
in the ./examples/
folder.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use \ConversionTools\ConversionClient;
// put token here from your Profile page at https://conversiontools.io/profile
$token = '';
$fileOrUrlInput = 'https://google.com';
$fileOutput = 'result.pdf';
$options = [];
$client = new ConversionClient($token);
try {
$client->convert('convert.website_to_pdf', $fileOrUrlInput, $fileOutput, $options);
} catch (Exception $e) {
print 'Exception: ' . $e->getMessage() . "\n";
}
use \ConversionTools\ConversionClient;
$client = new ConversionClient('<token>');
Where <token>
is API token from the account's Profile page https://conversiontools.io/profile.
$client = new ConversionClient($token);
try {
$client->convert('<conversion type>', $fileOrUrlInput, $fileOutput, $options);
} catch (Exception $e) {
print 'Exception: ' . $e->getMessage() . "\n";
}
Where
<conversion type>
is a specific type of conversion, from API Documentation.$fileOrUrlInput
is the filename of the input file, or URL of the file to convert (when applicable)$fileOutput
is the filename of the output file$options
is a PHP array with options for a corresponding converter, for example:
$options = ['delimiter' => 'tabulation'];
PHP version 5.4.0 or later.
List of available Conversion Types and corresponding conversion options can be found on the Conversion Tools API Documentation page.
Licensed under MIT.
Copyright (c) 2021 Conversion Tools