Created
May 5, 2019 22:10
-
-
Save georgestephanis/e8e89c7dceedbc9e7c9657f0c32d368a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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