Re: replace striing éèêà

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


|


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux