PHP Snippet 1:
foreach( $foreign_characters as $replace => $with )
{
$string = preg_replace($replace, $with, $string);
}
PHP Snippet 2:
class Replacer
{
/**
* List of character replacements
*/
static $foreign_characters = array(
'/ä|æ|?/' => 'ae',
'/ö|œ/' => 'oe',
'/ü/' => 'ue',
'/Ä/' => 'Ae',
'/Ü/' => 'Ue',
'/Ö/' => 'Oe',
'/À|Á|Â|Ã|Ä|Å|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?/' => 'A',
'/à|á|â|ã|å|?|?|?|?|?|ª|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?/' => 'a',
);
/**
* Replaces all foreign characters listed in
* self::$foreign_characters with their given counterparts
* @param $string string to replace characters in
*/
public static function replace_chars_in($string)
{
foreach( self::$foreign_characters as $replace => $with )
{
$string = preg_replace($replace, $with, $string);
}
return $string;
}
}
PHP Snippet 3:
echo Replacer::replace_chars_in("äÄfäüädasÖä?asd");
PHP Snippet 4:
function convert_accented_characters($str)
{
static $array_from, $array_to;
if ( ! is_array($array_from))
{
if (file_exists(APPPATH.'config/foreign_chars.php'))
{
include(APPPATH.'config/foreign_chars.php');
}
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php');
}
if (empty($foreign_characters) OR ! is_array($foreign_characters))
{
$array_from = array();
$array_to = array();
return $str;
}
$array_from = array_keys($foreign_characters);
$array_to = array_values($foreign_characters);
}
return preg_replace($array_from, $array_to, $str);
}