Created
April 13, 2014 02:59
-
-
Save luizventurote/10567179 to your computer and use it in GitHub Desktop.
Sanitize String - PHP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Sanitize String | |
* | |
* @param string $str string to be cleaned | |
* @return string new string without special characters | |
*/ | |
function sanitizeString($str) { | |
$str = preg_replace('/[áàãâä]/ui', 'a', $str); | |
$str = preg_replace('/[éèêë]/ui', 'e', $str); | |
$str = preg_replace('/[íìîï]/ui', 'i', $str); | |
$str = preg_replace('/[óòõôö]/ui', 'o', $str); | |
$str = preg_replace('/[úùûü]/ui', 'u', $str); | |
$str = preg_replace('/[ç]/ui', 'c', $str); | |
$str = preg_replace('/[,(),;:|!"#$%&/=?~^><ªº-]/', '_', $str); | |
$str = preg_replace('/[^a-z0-9]/i', '_', $str); | |
$str = preg_replace('/_+/', '_', $str); | |
return $str; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment