Okay I have a string:
$string = "ÉÄÑAsHHffdsfFJKLDWHU";
and I want to make it into:
$string = "eanashhffdsffjkldwhu";
I want to change all characters to a-z and space
Okay I have a string:
$string = "ÉÄÑAsHHffdsfFJKLDWHU";
and I want to make it into:
$string = "eanashhffdsffjkldwhu";
I want to change all characters to a-z and space
If it was just make the string all lower case that would be strtolower() but you want more than that. You will need to map which ASCI characters you want changed to what map characters you want them changed to. They just do a match and replace.
str_replace can take arrays. Have a look here
HTH
Bubble
For this, I would suggest strtr instead of str_replace.
I think you can just do this:
$string = strtr($string, "ÉÄÑAsHHffdsfFJKLDWHU", "eanashhffdsffjkldwhu");
There are more examples on the strtr page.
do it with an array
$change = array(
'É' => 'e',
'Ä' => 'a',
'Ñ' => 'n'
)
$str = "ÉÄÑ";
foreach($change AS $key=>$val){
$str = str_replace($key, $val, $str);
}
echo $str;
//will echo ean
hope that helps
adam
You don't even need to do it as seperate str_replaces, str_replace can handle arrays so
<?php
$from=array('É','Ä','Ñ');
$to=array('e','a','n');
$str='ÉÄÑ';
str_replace($from,$to,$str);
?>
HTH
Bubble
Yeah, but [man]strtr[/man] is most likely faster for bulk transliteration of single characters, and there's code on that page for the job besides.