note 96847 added to function.preg-replace

From: Date: Thu, 18 Mar 2010 22:50:08 +0000
Subject: note 96847 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-167180@lists.php.net to get a copy of this message
A utf-8 safe way to remove accents: <?php /** * UTF-8 Normalization of ASCII extended characters */ #require_once 'utf8.inc'; # http://hsivonen.iki.fi/php-utf8/ function normalize($string) { $ext = array(192, 193, 194, 195, 196, 197, 224, 225, 226, 227, 228, 229, 199, 231, 200, 201, 202, 203, 232, 233, 234, 235, 204, 205, 206, 207, 236, 237, 238, 239, 210, 211, 212, 213, 214, 216, 242, 243, 244, 245, 246, 248, 209, 241, 217, 218, 219, 220, 249, 250, 251, 252, 221, 255, 253); $norm = array(65, 65, 65, 65, 65, 65, 97, 97, 97, 97, 97, 97, 67, 99, 69, 69, 69, 69, 101, 101, 101, 101, 73, 73, 73, 73, 105, 105, 105, 105, 79, 79, 79, 79, 79, 79, 111, 111, 111, 111, 111, 111, 78, 110, 85, 85, 85, 85, 117, 117, 117, 117, 89, 121, 121); $string = db_UTF8::utf8tounicode($string); // Using array insersect is slower foreach ($ext as $k => $e) { if ($pos = array_search($e, $string)) { $string[$pos] = $norm[$k]; } } $string = db_UTF8::unicodetoutf8($string); return $string; } ---- Server IP: 64.71.164.2 Probable Submitter: 67.186.237.13 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/96847 Del: integrated -- https://master.php.net/note/delete/96847/integrated Del: useless -- https://master.php.net/note/delete/96847/useless Del: bad code -- https://master.php.net/note/delete/96847/bad+code Del: spam -- https://master.php.net/note/delete/96847/spam Del: non-english -- https://master.php.net/note/delete/96847/non-english Del: in docs -- https://master.php.net/note/delete/96847/in+docs Del: other reasons-- https://master.php.net/note/delete/96847 Reject -- https://master.php.net/note/reject/96847 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167180) next »