note 116551 deleted from function.strtr by salathe
| From: | salathe@php.net | Date: | Fri, 06 Feb 2015 12:56:46 +0000 |
| Subject: | note 116551 deleted from function.strtr by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-201603@lists.php.net to get a copy of this message | ||
Note Submitter: wissamelkik at gmail dot com
----
I was using the following function to normalize a string. The function
strtr
wasn't working. I had to add a header with charset: ISO-8859-1 to make it work.
PS: I had to reduce the size of the array to be able to post this note.
<?php
header("Content-Type: text/plain; charset=ISO-8859-1");
function normalizeChars($s) {
$replace = array(
'&' => 'and', '@' => 'at', '©'
=> 'c', '®' => 'r', 'Ã' => 'a',
'Ã' => 'a', 'Ã' => 'a', 'Ã' =>
'a', 'Ã
' => 'a', 'Ã' =>
'ae','Ã' => 'c',
'Ã' => 'e', 'Ã' => 'e', 'Ã' =>
'e', 'Ã' => 'i', 'Ã' => 'i',
'Ã' => 'i', 'Ã' => 'i', 'Ã' =>
'o', 'Ã' => 'o', 'Ã' => 'o',
'Ã' => 'o', 'Ã' => 'o',
'Ã' => 'o', 'Ã' => 'u', 'Ã' =>
'u', 'Ã' => 'u', 'Ã' => 'u',
'Ã' => 'y', 'Ã' => 'ss','Ã ' =>
'a', 'á' => 'a', 'â' => 'a',
'ä' => 'a', 'å' => 'a',
'æ' => 'ae','ç' => 'c', 'è' =>
'e', 'é' => 'e', 'ê' => 'e',
'ë' => 'e', 'ì' => 'i', 'Ã' =>
'i', 'î' => 'i', 'ï' => 'i',
'ò' => 'o', 'ó' => 'o',
'ô' => 'o', 'õ' => 'o', 'ö' =>
'o', 'ø' => 'o', 'ù' => 'u',
'ú' => 'u', 'ñ' => 'n',
);
return strtr($s, $replace);
}
$str = '<?xml version="1.0"
encoding="ISO-8859-1"?><data><id><![CDATA[5531]]></id><baños><![CDATA[0]]></baños></data>';
echo normalizeChars($str);
?>