note 16036 deleted from function.strtr by jimw
| From: | jimw@php.net | Date: | Fri, 14 Dec 2001 20:35:51 +0000 |
| Subject: | note 16036 deleted from function.strtr by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22763@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