Difference between revisions of "Custom Transliteration"

From WHMCS Documentation

(Created page with 'Transliteration is the practice of converting a text from one writing system into another in a systematic way. In WHMCS this is supported & can be used to automatically replace …')
 
m
Line 9: Line 9:
 
  function hook_transliterate($string) {
 
  function hook_transliterate($string) {
 
     $string = str_replace("ž","z",$string);
 
     $string = str_replace("ž","z",$string);
 +
    $string = str_replace("é","e",$string);
 
     return $string;
 
     return $string;
 
  }
 
  }

Revision as of 15:38, 15 November 2011

Transliteration is the practice of converting a text from one writing system into another in a systematic way.

In WHMCS this is supported & can be used to automatically replace characters in a clients profile data that would otherwise cause third party systems such as hosting control panels and domain registrars to reject the automated API requests containing those characters.

A default function included in WHMCS will automatically take care of and replace the most common special characters that cause problems for users but if you need to tailor it to your specific needs, then you can do so by creating a hook file as follows to override the default function, and specify your own custom character replacement process within it.

<?php

function hook_transliterate($string) {
    $string = str_replace("ž","z",$string);
    $string = str_replace("é","e",$string);
    return $string;
}

add_hook("Transliteration",1,"hook_transliterate");

?>

The code above can simply be copied and pasted into a new file and saved into the /includes/hooks/ folder with any name to take effect, and you can then customise the character replacements done by that function as desired and just need to return the converted string at the end of the call.