PHP/String/String Compare — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 07:07, 26 мая 2010

Compare string

<?
$string_1 = "00008";
$string_2 = "007";
$string_3 = "00008-OK";
if ($string_2 < $string_1){
  print("$string_2 is less than $string_1<BR>");
}
if ($string_3 < $string_2){
  print("$string_3 is less than $string_2<BR>");
}
if ($string_1 < $string_3){
  print("$string_1 is less than $string_3<BR>");
}
?>



strcasecmp: Binary safe case-insensitive string comparison

<?php
   $email1 = "admin@example.ru";
   $email2 = "ADMIN@example.ru";
   if (! strcasecmp($email1, $email2))
      print "The email addresses are identical!";
?>



String compare demo: =

 <?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";
  }
  ?>



String compare: equal

<?php
  $hobby = "Music";
  if ($hobby = "Music"){
     echo "You have an interesting hobby";
  }
?>



String compare with if statement

<html>
<head>
<title>Decisions</title>
</head>
<body>
<?php
     $str_ctrl_flow = "go";
   
     if(!strcmp($str_ctrl_flow, "go")) {
          print("string is \"go\"<br />");
     } else {
          print("Time to stop<br />");
          exit;
     }
   
     $str_ctrl_flow = "stop";
   
     if(!strcmp($str_ctrl_flow, "go")) {
          print("string is \"go\"<br />");
     } else {
          print("Time to stop<br />");
          exit;
     }
?>
</body>
</html>