Page tree
Skip to end of metadata
Go to start of metadata

 

Description

This function converts a buffer from one encoding language to another.

Examples 


 cPanel or Webmail Session URL
https://hostname.example.com:2083/cpsess##########/execute/Fileman/transcode?from_charset=utf-8&to_charset=us-ascii&content="hi"&discard_illegal=1&transliterate=1

 

Note:

This example calls the UAPI function via a cPanel session. For more information, read our Guide to UAPI documentation. 

 LiveAPI PHP Class
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
 
// Convert file from UTF-8 to ASCII.
$convert_file_encoding = $cpanel->uapi(
    'Fileman', 'transcode',
		array(
		'from_charset'		=> 'UTF-8',
		'to_charset'		=> 'ASCII',
		'content'			=> '"hi"',
		'discard_illegal'	=> '0',
		'transliterate'		=> '0',
  )
);

Note:

For more information, read our Guide to the LiveAPI System.

 

 LiveAPI Perl Module
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
 
# Convert file from UTF-8 to ASCII.
my $ convert_file_encoding = $cpliveapi->uapi(
 'Fileman', 'transcode',
		{
		'from_charset'		=> 'UTF-8',
		'to_charset'		=> 'ASCII',
		'content'			=> '"hi"',
		'discard_illegal'	=> '0',
		'transliterate'		=> '0',
		}
 );

Note:

For more information, read our Guide to the LiveAPI System.

 

 cPanel Template Toolkit
<!-- Get a hash of all the data, then display the charset value. -->
[% data = execute( 'Fileman', 'upload_files' {'from_charset' => 'UTF-8', 'to_charset' => 'ASCII', 'content' => '"hi", 'discard_illegal' => '1', 'translitertate' => '0',} ); %]
[% FOREACH q = data.path %]
     <p>
         [% q %]
     </p>
[% END %]
 
<!-- Get only a hash of the data. -->
[% execute('Fileman', 'upload_files' {'from_charset' => 'UTF-8', 'to_charset' => 'ASCII', 'content' => '"hi", 'discard_illegal' => '1', 'translitertate' => '0',}  ).data.path %]

Note:

For more information, read our Guide to Template Toolkit documentation. 

 

 Command Line
uapi --user=username Fileman transcode from_charset=utf-8 to_charset=us-ascii content=\"hi\" discard_illegal=1 transliterate=1

Notes:

  • You must URI-encode values.
  • username represents your account-level username.
  • For more information and additional output options, read our Guide to UAPI documentation or run the uapi --help command. 
  • We introduced this functionality in cPanel & WHM version 56.

 Output (JSON)
{  
   "messages":null,
   "errors":null,
   "status":1,
   "metadata":{  

  },
  "data": {
    "from_charset": "utf-8",
    "to_charset": "utf-8",
    "path": "/home/username/public_html/example.html"
  }
}

Note:

Use cPanel's API Shell interface (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.

   

Parameters

ParametersTypeDescriptionPossible valuesExample
contentstring

Required

The file's contents.

A string value."hi"
from_charsetstring

The file's current character set encoding.

 

Any cPanel-supported character set encoding.

UTF-8

 
to_charsetstring

The character set encoding in which to encode the file.

Any cPanel-supported character set encoding.

ASCII

 
discard_illegalBooleanWhether to discard any characters that do not transcode correctly.1
transliterateBooleanWhether to transcode invaid characters to valid characters in the new character set encoding.0

Returns

ReturnTypeDescriptionPossible valuesExample
contentstringThe file content.A string value."hi"
charsetstring

The file's new character set.

A cPanel-supported character set encoding.

ASCII