Replace Swedish characters åäö in string
This is some ways of removing the Swedish characters åäö in a string. Be sure that your editor is saving the file in UTF-8.
<?php
$string = "Åland är en ö i Östersjön";
$RemoveChars[] = '/å/';
$RemoveChars[] = '/ä/';
$RemoveChars[] = '/ö/';
$RemoveChars[] = '/Å/';
$RemoveChars[] = '/Ä/';
$RemoveChars[] = '/Ö/';
$ReplaceWith[] = 'a';
$ReplaceWith[] = 'a';
$ReplaceWith[] = 'o';
$ReplaceWith[] = 'A';
$ReplaceWith[] = 'A';
$ReplaceWith[] = 'O';
$text = preg_replace($RemoveChars, $ReplaceWith, $string);
echo $text;
?>
You might have to use ASCII code instead.
197, 196, 214 Å, Ä, Ö
229, 228, 246 å, ä, ö
<?php
$RemoveChars[] = '/'.chr(229).'/';
$RemoveChars[] = '/'.chr(228).'/';
$RemoveChars[] = '/'.chr(246).'/';
$RemoveChars[] = '/'.chr(197).'/';
$RemoveChars[] = '/'.chr(196).'/';
$RemoveChars[] = '/'.chr(214).'/';
$ReplaceWith[] = 'a';
$ReplaceWith[] = 'a';
$ReplaceWith[] = 'o';
$ReplaceWith[] = 'A';
$ReplaceWith[] = 'A';
$ReplaceWith[] = 'O';
?>
<?php
//In this form, strtr() does byte-by-byte translation
//Therefore, we are assuming a single-byte encoding here:
$addr = strtr($addr, "äåö", "aao");
?>
Knowledge keywords: