Created
June 30, 2013 09:35
-
-
Save paulund/5894523 to your computer and use it in GitHub Desktop.
A number of ways to compare string with PHP, used in the post http://www.paulund.co.uk/how-to-compare-strings-in-php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Using the == operator, Strings do not match is printed | |
if('string1' == 'STRING1') | |
{ | |
echo 'Strings match.'; | |
} else { | |
echo 'Strings do not match.'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Using the == operator, Strings match is printed | |
if('string1' == 'string1') | |
{ | |
echo 'Strings match.'; | |
} else { | |
echo 'Strings do not match.'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Both strings will match | |
if(strcasecmp('string1', 'string1') == 0) | |
{ | |
echo 'Strings match.'; | |
} else { | |
echo 'Strings do not match.'; | |
} | |
// Both strings will match even with different case | |
if(strcasecmp('string1', 'String1') == 0) | |
{ | |
echo 'Strings match.'; | |
} else { | |
echo 'Strings do not match.'; | |
} | |
// Both strings will match even with different case | |
if(strcasecmp('string1', 'STRING1') == 0) | |
{ | |
echo 'Strings match.'; | |
} else { | |
echo 'Strings do not match.'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// strcmp function, Strings match is printed | |
if(strcmp('string1', 'string1') == 0) | |
{ | |
echo 'Strings match.'; | |
} else { | |
echo 'Strings do not match.'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment