Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder grumpy's Avatar
    Join Date
    Oct 2006
    Location
    Visible light spectrum
    Posts
    121
    Thanks
    5
    Thanked 6 Times in 6 Posts

    search for vowels inside string

    hello,

    Would this work?:

    PHP Code:

    $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

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    strpos takes a string argument and not an array...using preg_match can simplyfy things

    PHP Code:
    if ( preg_match('/[aeiou]/i'$fname_out) > 
        
    && 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) > 
        
    && preg_match('/' join('|'$swear) . '/' $lname_out) > 0
        
    && preg_match('/[^a-z0-9]/i'$fname_out) > 
        
    && preg_match('/[^a-z0-9]/i'$lname_out) > ) {
    ...
    } else {
    ...

    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • Users who have thanked shyam for this post:

    grumpy (08-10-2008)

  • #3
    Regular Coder grumpy's Avatar
    Join Date
    Oct 2006
    Location
    Visible light spectrum
    Posts
    121
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Thank you very much indeed.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •