Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-25-2013, 02:22 PM   PM User | #1
cancer10
Regular Coder

 
Join Date: Jun 2006
Location: India
Posts: 795
Thanks: 210
Thanked 2 Times in 2 Posts
cancer10 can only hope to improve
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
__________________
http://outlineme.com/cancer10
cancer10 is offline   Reply With Quote
Old 01-25-2013, 02:28 PM   PM User | #2
kbluhm
Senior Coder

 
kbluhm's Avatar
 
Join Date: Apr 2007
Location: Philadelphia, PA, USA
Posts: 1,502
Thanks: 2
Thanked 258 Times in 254 Posts
kbluhm will become famous soon enough
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
)
__________________
ZCE

Last edited by kbluhm; 01-25-2013 at 02:42 PM..
kbluhm is offline   Reply With Quote
Old 01-25-2013, 02:34 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,652
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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 :'(
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 01-25-2013, 02:40 PM   PM User | #4
kbluhm
Senior Coder

 
kbluhm's Avatar
 
Join Date: Apr 2007
Location: Philadelphia, PA, USA
Posts: 1,502
Thanks: 2
Thanked 258 Times in 254 Posts
kbluhm will become famous soon enough
Haha, sorry... I had a simple answer, then got curious and did a bit more testing.
__________________
ZCE
kbluhm is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:16 PM.


Advertisement
Log in to turn off these ads.