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
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts

    Question Similar string not matched?

    Hi

    Can someone please explain why it prints 2?

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

    PFA code snippet.


    Thanks

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    There are special characters at the beginning of the first EMAIL string. When I copied/pasted the code above, I get 2. When I type everything out manually from scratch, I get 1. If I paste the code into a raw text field, I get what visually appears to be a tabbed space. Something like so:
    Code:
    if ('	EMAIL' == 'EMAIL'){
    So let's just split the strings by character and see what we get.
    PHP Code:
    $chars str_split'EMAIL' );
    print_r$chars );

    $chars array_map'ord'$chars );
    print_r$chars ); 
    First EMAIL string:
    Code:
    Array
    (
        [0] => ï
        [1] => »
        [2] => ¿
        [3] => E
        [4] => M
        [5] => A
        [6] => I
        [7] => L
    )
    Array
    (
        [0] => 239
        [1] => 187
        [2] => 191
        [3] => 69
        [4] => 77
        [5] => 65
        [6] => 73
        [7] => 76
    )
    Second EMAIL string:
    Code:
    Array
    (
        [3] => E
        [4] => M
        [5] => A
        [6] => I
        [7] => L
    )
    Array
    (
        [3] => 69
        [4] => 77
        [5] => 65
        [6] => 73
        [7] => 76
    )
    Last edited by kbluhm; 01-25-2013 at 03:42 PM.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Yeppers, the first email has utf-8 BOM in it:
    Code:
    � = 239
    � = 187
    � = 191
    E = 69
    M = 77
    A = 65
    I = 73
    L = 76
    
    E = 69
    M = 77
    A = 65
    I = 73
    L = 76
    Edit:
    Awww, Kbluhm edited just seconds before I finished :'(
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Haha, sorry... I had a simple answer, then got curious and did a bit more testing.


  •  

    Posting Permissions

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