Skip to content

Instantly share code, notes, and snippets.

@Langmans
Created December 7, 2015 10:17
Show Gist options
  • Save Langmans/4e9e33fed73b885a702e to your computer and use it in GitHub Desktop.
Save Langmans/4e9e33fed73b885a702e to your computer and use it in GitHub Desktop.
remove accented chars - all htmlentities charsets / encoding.
<?php
$specialchars =
array(
"\t" => '_',
"\r" => '_',
"\n" => '_',
' ' => '_',
':' => '.',
'`' => ''
)
+ get_html_translation_table( HTML_ENTITIES, ENT_QUOTES, 'UTF-8' )
+ get_html_translation_table( HTML_ENTITIES, ENT_QUOTES, 'ISO-8859-1' )
+ get_html_translation_table( HTML_ENTITIES, ENT_QUOTES, 'ISO-8859-15' )
+ get_html_translation_table( HTML_ENTITIES, ENT_QUOTES, 'ISO-8859-5' )
+ get_html_translation_table( HTML_ENTITIES, ENT_QUOTES, 'cp1251' )
+ get_html_translation_table( HTML_ENTITIES, ENT_QUOTES, 'cp1252' );
foreach ( $specialchars as $char => $entity ) {
if ( strpos( $entity, '#' ) ) {
$specialchars[ $char ] = '-';
} elseif ( preg_match( '@^&([a-zA-z]{1,2})(grave|acute|circ|tilde|uml|cedil|lig|slash);$@', $entity, $matches ) ) {
$specialchars[ $char ] = $matches[1];
} elseif ( preg_match( '@^&(.*);$@', $entity, $matches ) ) {
$specialchars[ $char ] = $matches[1];
} else {
$specialchars[ $char ] = '-';
}
}
$string = strtr( "blaÄAÜÏO `ìq.txt", $specialchars );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment