note 32820 added to function.str-split
| From: | kevin at oceania dot net | Date: | Sun, 08 Jun 2003 05:10:49 +0000 |
| Subject: | note 32820 added to function.str-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-49964@lists.php.net to get a copy of this message | ||
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;
?>
----
Manual Page -- http://www.php.net/manual/en/function.str-split.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32820
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32820&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32820&report=yes