Search code examples
phpternary-operatorstrpos

What's wrong with this strpos and ternary operator?


strpos($mydata,'Εntity') === false) ? 'normal' : 'other'

It returns always 'normal' even if

 $mydata="Entity: This data must work." 

Solution

  • As I though your string has a weird encoding if you take a look into a hex editor and compare the Entity from your string and from the strpos call you will see the difference:

    //string
    45 6e 74 69 74 79  
    //strpos call
    ce 95 6e 74 69 74 79 
    

    So to solve this now, just don't copy it from here on SO just write it normal with your keyboard and all should work fine. The proof here: http://3v4l.org/lbL4v