PHP code example of fossar / transcoder

1. Go to this page and download the library: Download fossar/transcoder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fossar / transcoder example snippets


use Ddeboer\Transcoder\Transcoder;

$transcoder = Transcoder::create();
$result = $transcoder->transcode('España', 'iso-8859-1');

use Ddeboer\Transcoder\MbTranscoder;

$transcoder = new MbTranscoder();

use Ddeboer\Transcoder\IconvTranscoder;

$transcoder = new IconvTranscoder();

$transcoder->transcode('España');

use Ddeboer\Transcoder\Transcoder;

$isoTranscoder = Transcoder::create('iso-8859-1');

use Ddeboer\Transcoder\Transcoder;

$transcoder->transcode('España', 'iso-8859-1', 'UTF-8');

use Ddeboer\Transcoder\Exception\UndetectableEncodingException;
use Ddeboer\Transcoder\Exception\UnsupportedEncodingException;
use Ddeboer\Transcoder\Exception\IllegalCharacterException;

$input = 'España';

try {
    $transcoder->transcode($input, 'utf-8', 'not-a-real-encoding');
} catch (UnsupportedEncodingException $e) {
    // ‘not-a-real-encoding’ is an unsupported encoding
}

try {
    $transcoder->transcode('Illegal quotes: ‘ ’', 'utf-8', 'iso-8859-1');
} catch (IllegalCharacterException $e) {
    // Curly quotes ‘ ’ are illegal in ISO-8859-1
}

try {
    $transcoder->transcode($input);
} catch (UndetectableEncodingException $e) {
    // Failed to automatically detect $input’s encoding (mb) or not a valid string in current locale locale (iconv)
}