note 98669 deleted from function.strtr by googleguy
| From: | googleguy@php.net | Date: | Fri, 12 Apr 2013 01:26:46 +0000 |
| Subject: | note 98669 deleted from function.strtr by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194461@lists.php.net to get a copy of this message | ||
Note Submitter: sales at mk2solutions dot com
----
This is what we use for prepping data that is going to be used for shortURLs or just needs to be
completely cleaned
<?php
$GLOBALS['normalizeChars'] = array(
'Å '=>'S', 'Å¡'=>'s',
'Ã'=>'Dj','Ž'=>'Z',
'ž'=>'z', 'Ã'=>'A',
'Ã'=>'A', 'Ã'=>'A',
'Ã'=>'A', 'Ã'=>'A',
'Ã
'=>'A', 'Ã'=>'A',
'Ã'=>'C', 'Ã'=>'E',
'Ã'=>'E', 'Ã'=>'E',
'Ã'=>'E', 'Ã'=>'I',
'Ã'=>'I', 'Ã'=>'I',
'Ã'=>'I', 'Ã'=>'N',
'Ã'=>'O', 'Ã'=>'O',
'Ã'=>'O', 'Ã'=>'O',
'Ã'=>'O', 'Ã'=>'O',
'Ã'=>'U', 'Ã'=>'U',
'Ã'=>'U', 'Ã'=>'U',
'Ã'=>'Y', 'Ã'=>'B',
'Ã'=>'Ss','Ã '=>'a',
'á'=>'a', 'â'=>'a',
'ã'=>'a', 'ä'=>'a',
'å'=>'a', 'æ'=>'a',
'ç'=>'c', 'è'=>'e',
'é'=>'e', 'ê'=>'e',
'ë'=>'e', 'ì'=>'i',
'Ã'=>'i', 'î'=>'i',
'ï'=>'i', 'ð'=>'o',
'ñ'=>'n', 'ò'=>'o',
'ó'=>'o', 'ô'=>'o',
'õ'=>'o', 'ö'=>'o',
'ø'=>'o', 'ù'=>'u',
'ú'=>'u', 'û'=>'u',
'ý'=>'y', 'ý'=>'y',
'þ'=>'b', 'ÿ'=>'y',
'Æ'=>'f'
);
function cleanForShortURL($toClean) {
$toClean = str_replace('&', '-and-', $toClean);
$toClean = trim(preg_replace('/[^\w\d_ -]/si', '', $toClean));//remove all
illegal chars
$toClean = str_replace(' ', '-', $toClean);
$toClean = str_replace('--', '-', $toClean);
return strtr($toClean, $GLOBALS['normalizeChars']);
}
This process cleans up any special characters and also coverts strings to a readable safe URL
format.
?>