Skip to content

Instantly share code, notes, and snippets.

@BlaM
Created March 23, 2017 12:58
Show Gist options
  • Save BlaM/ba0b5c68c4cdec5a6020cd5970598ea6 to your computer and use it in GitHub Desktop.
Save BlaM/ba0b5c68c4cdec5a6020cd5970598ea6 to your computer and use it in GitHub Desktop.
<?php
// http://de.wikipedia.org/wiki/K%C3%B6lner_Verfahren
function SoundKoeln($str) {
$buf = preg_replace('/[0-9]+/', '', $str);
$buf = str_replace(array('DSC', 'TSC'), array('8', '8'), $buf);
if (substr($buf, 0, 2) == 'CL') $buf = '45' . substr($buf, 2);
if (substr($buf, 0, 2) == 'CR') $buf = '47' . substr($buf, 2);
$buf = str_replace(array('PH', 'CH', 'CK', 'CX', 'KX', 'QX', 'CA', 'CO', 'CU', 'DC', 'DS', 'DZ', 'SC', 'TC', 'TS', 'TZ'),
array('3', '4', '4', '4', '4', '40', '40', '40', '8', '8', '8', '8', '8', '8', '8', '8'),
$buf);
$buf = str_replace(array('A','E','H','I','J','Y','O','U','B','P','D','T','F','V','W','G','K','Q','X', 'L','M','N','R','C','S','Z'),
array('0','0','0','0','0','0','0','0','1','1','2','2','3','3','3','4','4','4','48','5','6','6','7','8','8','8'),
$buf);
$buf = preg_replace('/(.)\1+/', '\1', $buf);
$buf = substr($buf, 0, 1) . str_replace('0', '', substr($buf, 1));
return $buf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment