...

View Full Version : search for vowels inside string



grumpy
08-10-2008, 02:58 PM
hello,

Would this work?:




$fname = "Bob";
$lname = "Costas";

$vowels = array ('a', 'e', 'i', 'o', 'u');
$numbers = array (1,2,3,4,5,6,7,8,9);
$swear = array ('swearword1', 'swearword2', 'swearwordX');
$extra_chars = array ('!', '#', '%'...);

if (((strpos($fname_out, $vowels) !== false) && (strpos($lname_out, $vowels) !== false)) && ((strpos($fname_out, $numbers) !== false) && (strpos($lname_out, $numbers) !== false)) && ((strpos($fname_out, $swear) !== false) && (strpos($lname_out, $swear)) && ((strpos($lname_out, $extra_chars) !== false) && (strpos($fname_out, $extra_chars) !== false)))
{
#proceed
}
else
{
#abort
}



Do I need to use ereg or something else instead? How can I validate for all those !"#$%&... characters without declaring them all? Is there a pre-built function for them or for swear words as well in php?

Thanks a bunch :)

shyam
08-10-2008, 06:41 PM
strpos (http://php.net/strpos)takes a string argument and not an array...using preg_match can simplyfy things


if ( preg_match('/[aeiou]/i', $fname_out) > 0
&& preg_match('/[aeiou]/i', $lname_out) > 0
&& preg_match('/[0-9]/', $fname_out) > 0
&& preg_match('/[0-9]/', $lname_out) > 0
&& preg_match('/' . join('|', $swear) . '/' , $fname_out) > 0
&& preg_match('/' . join('|', $swear) . '/' , $lname_out) > 0
&& preg_match('/[^a-z0-9]/i', $fname_out) > 0
&& preg_match('/[^a-z0-9]/i', $lname_out) > 0 ) {
...
} else {
...
}

grumpy
08-10-2008, 08:19 PM
Thank you very much indeed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum