Re: replace striing éèêà

From: Date: Mon, 06 Jun 2005 09:42:10 +0000
Subject: Re: replace striing éèêà
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-216468@lists.php.net to get a copy of this message
John Taylor-Johnston wrote:
Can someone show me how to get rid of international characters in $string? Is there a function already made?
the acute/grave accents on the chars are called 'diacritics'
You cannot use accented characters in a name reference : <a name="montréal">. I guess this below is a start. Is there a better way? John http://ca.php.net/manual/en/function.str-replace.php $string = "àâéèç"; |$find = array("à", "â", "é", "è", "ç"); ||$||replacewith|| = array("a", "a", "e", "e", "c");|| ||||$onlyconsonants = str_replace($vowels, $replacewith, $string);
<?php // you could do something like: function getUndiacritical($word) { $base_drop_char_match = array('^', '$', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '-', '~', '+', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!'); $base_drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' , ' ', ' ', ' ', ' ', ' ', ' '); $xtr_drop_char_match = array('à', 'â', 'ä', 'æ', 'è', 'ê', 'ì', 'î', 'ð', 'ò', 'ô', 'ö', 'ø', 'ú', 'ü', 'ß', 'á', 'ã', 'å', 'ç', 'é', 'ë', 'í', 'ï', 'ñ', 'ó', 'õ', 'ù', 'û', 'ý', 'ÿ'); $xtr_drop_char_replace = array('a', 'a', 'a', 'a', 'e', 'e', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 's', 'a', 'a', 'a', 'c', 'e', 'e', 'i', 'i', 'n', 'o', 'o', 'u', 'u', 'y', 'y'); $drop_char_match = array_merge( $base_drop_char_match, $xtr_drop_char_match ); $drop_char_replace = array_merge( $base_drop_char_replace, $xtr_drop_char_replace ); return str_replace($drop_char_match, $drop_char_replace, $word); } // alternatively function getUndiacritical2($word) { $base_drop_char_match = array('^', '$', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '-', '~', '+', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!'); $base_drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' , ' ', ' ', ' ', ' ', ' ', ' '); $xtr_drop_char_match = array('à', 'â', 'ä', 'æ', 'è', 'ê', 'ì', 'î', 'ð', 'ò', 'ô', 'ö', 'ø', 'ú', 'ü', 'ß', 'á', 'ã', 'å', 'ç', 'é', 'ë', 'í', 'ï', 'ñ', 'ó', 'õ', 'ù', 'û', 'ý', 'ÿ'); $xtr_drop_char_replace = array('a', 'a', 'a', 'a', 'e', 'e', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 's', 'a', 'a', 'a', 'c', 'e', 'e', 'i', 'i', 'n', 'o', 'o', 'u', 'u', 'y', 'y'); $drop_char_match = join('',array_merge( $base_drop_char_match, $xtr_drop_char_match )); $drop_char_replace = join('',array_merge( $base_drop_char_replace, $xtr_drop_char_replace )); return strtr($drop_char_match, $drop_char_replace, $word); } ?> I doubt either of these funcs is perfect but it hopefully gives you a clue in the right redirection. rgds, Jochem
|


« previous php.general (#216468) next »