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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post

    Why isn't the if comparision working?

    This always seems to return as true..

    PHP Code:
    if (strtolower($searchperson) == strtolower('$first') or strtolower('$last') or strtolower('$first $last')) { 
    Any ideas why?

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    anything within single quotes is ignored by PHP ... e.g.
    PHP Code:
    <?
    $first
    ='blah ';
    echo 
    $first
    echo 
    "$first";
    echo 
    '$first';
    ?>
    e.g.
    <?
    if (
       
    strtolower($searchperson) == strtolower$first ) || 
       
    strtolower($searchperson) == strtolower$last ) || 
       
    strtolower($searchperson) == strtolower("$first $last")
    ){
    //match
    }
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    I initially tried it with no quotes around them but then I got errors so then I tried single & double quotes around them & both those always returned true results every time.

  • #4
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Hmmmm.... I tried doing it that way before on the single line but it didn't work; however that works.

    Cheers!


  •  

    Posting Permissions

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