Sign in to follow this  
Marcs

MySQL Umlaute umwandeln

Recommended Posts

Welche Möglichkeiten gibt es automatisch Umlaute in einer Datenbank umzuwandeln?

Aktuell: In der Datenbank existiert eine Tabelle mit mehreren tausend Einträgen, dort soll in gewissen Spalten nach diesen Umlauten gesucht werden und anschliessend der Umlaut ersetzt werden. Das Ganze soll alle 10 min automatisch geschehen.

ö --> oe
ü --> ue
ä --> ae

Wie kann man das am einfachsten realisieren? huh.gif

Share this post


Link to post
Share on other sites
Weder schön noch besonders perfomant (aber am einfachsten smile.gif):

CODE
UPDATE tabelle SET spalte = REPLACE(REPLACE(REPLACE(spalte, 'ö', 'oe'), 'ü', 'ue'), 'ä', 'ae')


Du solltest versuchen, das UPDATE auf die Zeilen zu beschränken, die sich wirklich seit der letzten Ersetzung geändert haben.

Share this post


Link to post
Share on other sites
QUOTE (Flips @ Mi 28.04.2010, 08:24)
Du solltest versuchen, das UPDATE auf die Zeilen zu beschränken, die sich wirklich seit der letzten Ersetzung geändert haben.

@easyswiss

bitte bitte

warum reinschreiben und später "korrigieren"?

schon beim reinschreiben das richtige reinschreiben
CODE

$query = "INSERT INTO components_magazin ";

$query.= " SET ts= $ts ";
$query.= " , headline = '".$_POST[headline]."'";
$query.= " , filename = '".hl2fn($_POST[headline],1)."'";
mysql_query($query) or die("<b>$query</b>:<br> " . mysql_error());


wegen der Sicherheit vielleicht besser
CODE

$query = "INSERT INTO components_magazin ";

$query.= " SET ts= $ts ";
$query.= " , headline = '".addsleshes(stripslashes($_POST[headline]))."'";
$query.= " , filename = '".addsleshes(hl2fn(stripslashes($_POST[headline],1)))."'";
mysql_query($query) or die("<b>$query</b>:<br> " . mysql_error());



Bei mir weden Überschriften zu Dateinamen
= Headline 2 Filename

CODE

function hl2fn($headline, $low=0)

{

             $headline = hl2fn2(trim($headline));

 if ( $low ) $headline = strtolower( $headline );

 return(     $headline                         );

}


function hl2fn2($headline)

{

//        $headline= strtok($headline, " ");

       $headline= str_replace(chr(153), " TM", $headline );

       $headline= str_replace(chr(232), "e", $headline );

       $headline= str_replace(chr(233), "e", $headline );

       $headline= str_replace(chr(234), "e", $headline );

       $headline= str_replace(chr(235), "e", $headline );

       $headline= str_replace(chr(174), "R", $headline );

       $headline= str_replace("€", "e", $headline );

       $headline= str_replace("`", " ", $headline );

       $headline= str_replace("²", "2", $headline );

       $headline= str_replace("_", " ", $headline );

       $headline= str_replace('„', " ", $headline );

       $headline= str_replace('”', " ", $headline );

       $headline= str_replace('"', " ", $headline );

       $headline= str_replace("*", " ", $headline );

       $headline= str_replace("?", " ", $headline );

       $headline= str_replace("!", " ", $headline );

       $headline= str_replace("&", " ", $headline );

       $headline= str_replace("%", " ", $headline );

       $headline= str_replace("@", " ", $headline );

       //$headline= str_replace("|", " ", $headline );

       $headline= str_replace(",", " ", $headline );

       $headline= str_replace("=", " ", $headline );

//        $headline= str_replace("-", "", $headline );

       $headline= str_replace("«", " ", $headline );

       $headline= str_replace("»", " ", $headline );

       $headline= str_replace("<", " ", $headline );

       $headline= str_replace(">", " ", $headline );

       $headline= str_replace("(", " ", $headline );

       $headline= str_replace(")", " ", $headline );

       $headline= str_replace("]", " ", $headline );

       $headline= str_replace("[", " ", $headline );

       $headline= str_replace("+", " ", $headline );

       $headline= str_replace("'", " ", $headline );

       $headline= str_replace(";", " ", $headline );

       $headline= str_replace(":", " ", $headline );

       $headline= str_replace("ß", "ss", $headline );

       $headline= str_replace("ä", "ae", $headline );

       $headline= str_replace("ö", "oe", $headline );

       $headline= str_replace("ü", "ue", $headline );

       $headline= str_replace("Ä", "AE", $headline );

       $headline= str_replace("Ö", "OE", $headline );

       $headline= str_replace("Ü", "UE", $headline );

       

       $headline= str_replace("à", "a", $headline );



       $headline= str_replace("\n", " ", $headline );

       $headline= str_replace("\r", " ", $headline );

       $headline= str_replace("\\", " ", $headline );

       $headline= str_replace("/", " ", $headline );

       $headline= str_replace("#", " ", $headline );

       $headline= trim       (          $headline );

       $i=strlen($headline);

while($i--)

{

 if ( ord($headline{$i})>127 ) $headline{$i}=' ';

}

      $headline= str_replace(" ", "-", $headline );

       $headline= str_replace("--", "-", $headline );

       $headline= str_replace("--", "-", $headline );

       $headline= str_replace("--", "-", $headline );

       $headline= str_replace("--", "-", $headline );

       $headline= str_replace("--", "-", $headline );

       $headline= str_replace("--", "-", $headline );

       $headline= str_replace("--", "-", $headline );

       $headline= str_replace("--", "-", $headline );



 return($headline);

}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this