problems with Umlaut !?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dkizerian
Forum Newbie
Posts: 7
Joined: Thu Sep 12, 2002 3:32 pm
Location: SLC UTah

problems with Umlaut !?

Post by dkizerian »

Hi, I am having problems with Umlauts (Ö,ö) being used by people filling in information on a form. Is there an easy way to catch these and convert them to their respective non-umlauted Vowels?
:?:
Thanks
Dave K
SLC Utah
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

i don't believe there is a built in function to do that.. you'll probably have to do it manually :\ what exactly is the problem you're having?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

try something like

Code: Select all

$bad = array("Ö", "ö", "ô");
$good = array("O", "o", "o");
$string = str_replace($bad, $good, $string);
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

Code: Select all

<?
function convert($str) {
  $str = htmlentities($strї0]);
  return $strї1];
}
echo preg_replace_callback("/ї\xC0-\xFF]/",convert,$str);
?>
will replace hex xC0 through xFF which covers all of the characters including umlauts, accents etc.

http://www.htmlhelp.com/reference/html4 ... atin1.html is the site i used with all of them listed with their hex incase you want to single out chars.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

nice one, dusty. :lol:
dkizerian
Forum Newbie
Posts: 7
Joined: Thu Sep 12, 2002 3:32 pm
Location: SLC UTah

Post by dkizerian »

Thanks, between your help, and looking at a similar function I made years ago in javascript I was able to get it working the way I wanted
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

htmlentites() converts ä ö ü as well to $auml; ...
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

that's all my script is doing, but rather than printing the full entity; it's grabbing the second letter which is always the normal letter (a, o, u, etc).
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

htmlentites() is porbably faster... Cos it doesn't need to load Perl Reg Expression module.
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

hmm.. read the first post. he wants to change each umlaut to it's respective vowel. using htmlentities just changes it to just that.. an entity ie: Ä = &Auml

the preg function is locating the characters then sending it to the function that uses htmlentities to grab the 2nd letter of the output which in the example used above would be A.

if there is a way to do that with only htmlentities() please explain.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

OK, so there isn't a way to do it except using str_replace or preg_replace or ereg_replace then...
Post Reply