note 32820 deleted from function.str-split by philip

From: Date: Sat, 14 Jun 2003 15:43:23 +0000
Subject: note 32820 deleted from function.str-split by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-50342@lists.php.net to get a copy of this message
Note Submitter: kevin@oceania.net ---- This simple example shows how str_split() can be used to filter out un-wanted characters from a string. handy for passwords etc. <?php // just so we know it is broken error_reporting(E_ALL); // string to split $string = 'this string 97 must be (^ chars a to z only WITH NO CAPS'; // put the string into an array $string_array = str_split($string); // our new string $new_string = ''; // loop through the array foreach($string_array as $char) { // check if each char is a lower case member of the alphabet or a space if(($char >= 'a' && $char <= 'z') || $char==' ') { // write the good chars the new string $new_string .= $char; } } // echo the new string echo $new_string; ?>

« previous php.notes (#50342) next »