note 16036 added to function.strtr

From: Date: Sat, 13 Oct 2001 20:28:13 +0000
Subject: note 16036 added to function.strtr
Groups: php.notes 
Request: Send a blank email to php-notes+get-18891@lists.php.net to get a copy of this message
Incase anyone was wondering what the french guy/girl said up there, i thought i'd help out a little... ----------------------- FRENCH 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 :) ----------------------- -----------------------ENGLISH After searching in vain for a built-in function to do it (is there one?), I finally just simply created that would only allow certain characters in a 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; } Example below: $username = removechars($username,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.0123456789"); You could change the string for your own use of course. ----------------------- That's my contribution to this great site (for now), I am not exactly a pro @ PHP, but i do love it, and i love this site. Finally found some way i could contribute! -PL -- http://www.php.net/manual/en/function.strtr.php http://master.php.net/manage/user-notes.php?action=edit+16036 http://master.php.net/manage/user-notes.php?action=delete+16036 http://master.php.net/manage/user-notes.php?action=reject+16036

« previous php.notes (#18891) next »