User Tools

Site Tools


apps:php

PHP

Replace umlauts

!! This is really old, don't use it !! see comment below

function convertUmlaute($text){
   $pattern1="/ä/";
   $replace1="ä";
   $text=preg_replace($pattern1,$replace1, $text);
   $pattern2="/ö/";
   $replace2="ö";
   $text=preg_replace($pattern2,$replace2, $text);
   $pattern3="/ü/";
   $replace3="ü";
   $text=preg_replace($pattern3,$replace3, $text);
   $pattern1a="/Ä/";
   $replace1a="Ä";
   $text=preg_replace($pattern1a,$replace1a, $text);
   $pattern2a="/Ö/";
   $replace2a="Ö";
   $text=preg_replace($pattern2a,$replace2a, $text);
   $pattern3a="/Ü/";
   $replace3a="Ü";
   $text=preg_replace($pattern3a,$replace3a, $text);
   $pattern4="/ß/";
   $replace4="ß";
   $text=preg_replace($pattern4,$replace4, $text);
   return $text;
}

This function uses preg_replace, which works with regular expressions. For better performance I recommend to use str_replace. A short example:

$text = str_replace("ä", "ä", $text);
apps/php.txt · Last modified: 2014-12-18 20:08 by 127.0.0.1