SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    736
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Question Similar string not matched?

    Hi

    Can someone please explain why it prints 2?

    Code:
    <?php
    if ('EMAIL' == 'EMAIL'){
    print "1";
    }else{
    print "2";
    }
    ?>



    Thanks

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    It shouldnt.

    You sure you're copying and pasting correctly?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    @cancer10 ; surely you are over-simplifying your code when pasting it here, because I can't see any valid reason to have that sort of IF statement as presented in a production code base.

    Can you provide the actual IF statement so we can see the variables in use, how they are assigned, etc? As chances are the problem is you are assuming its value is 'EMAIL' which should equal 'EMAIL' but in all reality it isn't. Have you done a var_dump($var) to see if it really did contain 'EMAIL'?
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  4. #4
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    736
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    That IS the actual thing, and I posted it here because I could not find any reason why it would not match. I mean both are simple strings. If you copy/paste my above code and try it on ur end, it will not work.

    I just wanna know the reason.


    Thanks

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cancer10 View Post
    That IS the actual thing, and I posted it here because I could not find any reason why it would not match. I mean both are simple strings. If you copy/paste my above code and try it on ur end, it will not work.

    I just wanna know the reason.


    Thanks
    You have a BOM in your first 'EMAIL' string. If you copy and paste your code into Notepad++ you get the following:
    PHP Code:
    <?php
    if ('?EMAIL' == 'EMAIL'){
    print 
    "1";
    }else{
    print 
    "2";
    }
    ?>
    Remove the ? and it works fine. So just re-type your text and it will work.
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  6. #6
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    736
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    BOM?

  7. #7
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Err, wrong terminology on my part, but I'll link to BOM anyway, because it is good to know.

    Chances are you have a unicode or similar character hidden there next to the E or after the ' that doesn't show up in ASCII. Just wanted to correct myself, as others would
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  8. #8
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    736
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your kind help


Bookmarks

Posting Permissions

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