Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save georgestephanis/e8e89c7dceedbc9e7c9657f0c32d368a to your computer and use it in GitHub Desktop.

Select an option

Save georgestephanis/e8e89c7dceedbc9e7c9657f0c32d368a to your computer and use it in GitHub Desktop.
<?php
function python_slug( $str ) {
$str = Normalizer::normalize( $str, Normalizer::FORM_KD );
$str = preg_replace( '~[\x00-\x1F\x80-\xFF]~', '', $str );
$str = preg_replace( '~[^\w\s-]~', '', $str );
$str = strtolower( trim( $str ) );
return preg_replace( '~[-\s]+~', '-', $str );
}
function clean_company_names_to_slugs( $str ) {
$str = python_slug( $str );
$endings = array(
'',
'ag',
'as',
'bv',
'co',
'coltd',
'com',
'company',
'corp',
'corporation',
'de\-cv',
'gmbh',
'group',
'inc',
'kg',
'kk',
'ltd',
'ltda',
'limited',
'llc',
'llp',
'plc',
'pt',
'pte',
'pty',
'pvt',
'sdn\-bhd',
'sa',
'usa',
);
do {
$prev = $str;
$str = preg_replace( '~\-(' . implode( '|', $endings ) . ')$~', '', $prev );
} while ( $prev !== $str );
return $str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment