PHP/String/String Compare
Содержание
Compare string
<source lang="html4strict">
<? $string_1 = "00008"; $string_2 = "007"; $string_3 = "00008-OK"; if ($string_2 < $string_1){
print("$string_2 is less than $string_1
");
} if ($string_3 < $string_2){
print("$string_3 is less than $string_2
");
} if ($string_1 < $string_3){
print("$string_1 is less than $string_3
");
} ?>
</source>
strcasecmp: Binary safe case-insensitive string comparison
<source lang="html4strict">
<?php
$email1 = "admin@example.ru"; $email2 = "ADMIN@example.ru"; if (! strcasecmp($email1, $email2)) print "The email addresses are identical!";
?>
</source>
String compare demo: =
<source lang="html4strict">
<?php $ilike = "Dance"; if ($ilike = "Music"){ echo "Do you like singing?"; }elseif ($ilike = "Dance") { echo "Do you like dancing?"; }else{ echo "You like neither music nor dance"; } ?> </source>
String compare: equal
<source lang="html4strict">
<?php
$hobby = "Music"; if ($hobby = "Music"){ echo "You have an interesting hobby"; }
?>
</source>
String compare with if statement
<source lang="html4strict">
<html> <head> <title>Decisions</title> </head> <body> <?php
$str_ctrl_flow = "go"; if(!strcmp($str_ctrl_flow, "go")) { print("string is \"go\"
"); } else { print("Time to stop
"); exit; } $str_ctrl_flow = "stop"; if(!strcmp($str_ctrl_flow, "go")) { print("string is \"go\"
"); } else { print("Time to stop
"); exit; }
?> </body> </html>
</source>