Click to See Complete Forum and Search --> : alpha only


esm
08-16-2003, 06:47 PM
I have a variable that can be anything. and I mean anything.

Alpha, numeric, special characters (!,$,%,&, spaces etc )

how can I pull and use just 3 or 4 alpha characters?

pyro
08-16-2003, 08:53 PM
This will pull the first 4 alphabetic characters:

<?PHP
$str = '$a2bc:1#2[]d3e';
$newstr = "";
$str = preg_split("/[^a-zA-Z]/", $str);
foreach ($str as $char) {
if (ctype_alpha($char)) {
$newstr .= $char;
}
}
$new_str = substr($newstr,0,4); #take from character 0 to character 4
echo $new_str;
?>

esm
08-17-2003, 08:59 AM
thnaks, pyro! worked like a charm...

pyro
08-17-2003, 09:15 AM
You're welcome... :)