note 116551 added to function.strtr
| From: | wissamelkik at gmail dot com | Date: | Wed, 21 Jan 2015 12:32:11 +0000 |
| Subject: | note 116551 added to function.strtr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201488@lists.php.net to get a copy of this message | ||
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);
?>
----
Server IP: 72.52.91.14
Probable Submitter: 89.108.160.58
----
Manual Page -- http://php.net/manual/en/function.strtr.php
Edit -- https://master.php.net/note/edit/116551
Del: integrated -- https://master.php.net/note/delete/116551/integrated
Del: useless -- https://master.php.net/note/delete/116551/useless
Del: bad code -- https://master.php.net/note/delete/116551/bad+code
Del: spam -- https://master.php.net/note/delete/116551/spam
Del: non-english -- https://master.php.net/note/delete/116551/non-english
Del: in docs -- https://master.php.net/note/delete/116551/in+docs
Del: other reasons-- https://master.php.net/note/delete/116551
Reject -- https://master.php.net/note/reject/116551
Search -- https://master.php.net/manage/user-notes.php