note 42454 modified in function.str-replace by aidan
| From: | aidan@php.net | Date: | Fri, 25 Jun 2004 06:03:20 +0000 |
| Subject: | note 42454 modified in function.str-replace by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71632@lists.php.net to get a copy of this message | ||
this is a rather long and obvious solution to converting non-english chars where str_replace fails.
<?php
function euro_chars($str)
{
$tmp = "";
for($i = 0; $i < strlen($str); $i++) {
switch(ord($str[$i])) {
case 192: case 193: //À Á
$tmp .= "A";
break;
case 200: case 201: //È É
$tmp .= "E";
break;
case 204: case 205: //Ì Í
$tmp .= "I";
break;
case 210: case 211: //Ò Ó
$tmp .= "O";
break;
case 217: case 218: //Ù Ú
$tmp .= "U";
break;
case 224: case 225: //à á
$tmp .= "a";
break;
case 232: case 233: //è é
$tmp .= "e";
break;
case 236: case 237: //ì í
$tmp .= "i";
break;
case 242: case 243: //ò ó
$tmp .= "o";
break;
case 249: case 250: //ù ú
$tmp .= "u";
break;
case 241: //ñ
$tmp .= "n";
break;
case 209: //Ñ
$tmp .= "N";
break;
case 231: //ç
$tmp .= "c";
break;
case 199: //Ç
$tmp .= "C";
break;
case 128: //
$tmp .= "EU";
break;
default:
$tmp .= (string)$str[$i];
break;
}
}
return($tmp);
}
?>
--was--
this is a rather long and obvious solution to converting non-english chars where str_replace fails.
function euro_chars($str)
{
$tmp = "";
for($i = 0; $i < strlen($str); $i++) {
switch(ord($str[$i])) {
case 192: case 193: //À Á
$tmp .= "A";
break;
case 200: case 201: //È É
$tmp .= "E";
break;
case 204: case 205: //Ì Í
$tmp .= "I";
break;
case 210: case 211: //Ò Ó
$tmp .= "O";
break;
case 217: case 218: //Ù Ú
$tmp .= "U";
break;
case 224: case 225: //à á
$tmp .= "a";
break;
case 232: case 233: //è é
$tmp .= "e";
break;
case 236: case 237: //ì í
$tmp .= "i";
break;
case 242: case 243: //ò ó
$tmp .= "o";
break;
case 249: case 250: //ù ú
$tmp .= "u";
break;
case 241: //ñ
$tmp .= "n";
break;
case 209: //Ñ
$tmp .= "N";
break;
case 231: //ç
$tmp .= "c";
break;
case 199: //Ç
$tmp .= "C";
break;
case 128: //
$tmp .= "EU";
break;
default:
$tmp .= (string)$str[$i];
break;
}
}
return($tmp);
}
http://php.net/manual/en/function.str-replace.php