note 116551 added to function.strtr

From: 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( '&amp;' => '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

« previous php.notes (#201488) next »