note 13890 deleted from function.strtr by jimw

From: Date: Fri, 14 Dec 2001 20:34:59 +0000
Subject: note 13890 deleted from function.strtr by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22761@lists.php.net to get a copy of this message
Après avoir vainement cherché une fonction built-in pour le faire (à moins qu'il y en ait une ?), j'ai fini par simplement créer une fonction pour n'authoriser que certains caractères dans une string: Function removechars($string,$authorised){ $string = trim($string); for ($i = 0; $i < strlen($string); $i++) { $table[$i] = substr($string,$i,1); } #for while (list ($line_num, $line) = each ($table)) { if ($line_num < strlen($string)) {$pos = strpos($authorised,$line);} if (strlen($pos) == 0) {$table[$line_num] = "";} } #while $string = implode($table,''); return $string; } donc par example après: $username = removechars($username,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.0123456789"); vous renverra la string purgé des méchants caractères importuns, vala :)

« previous php.notes (#22761) next »