GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Aug-2015, 05:43
beingchinmay beingchinmay is offline
Account Disabled
 
Join Date: Aug 2015
Posts: 3
beingchinmay is an unknown quantity at this point

How To Compare Two Strings with Comparison Operators in PHP?


PHP supports 3 string comparison operators, <, ==, and >, that generates Boolean values. Those operators use ASCII values of characters from both strings to determine the comparison results. Here is a PHP script on how to use comparison operators ....

PHP Code:

<?php
$a = "PHP is a scripting language.";
$b = "PHP is a general-purpose language.";
if ($a > $b) {
  print('$a > $b is true.'."
");
} else {
  print('$a > $b is false.'."
");
}
if ($a == $b) {
  print('$a == $b is true.'."
");
} else {
  print('$a == $b is false.'."
");
}
if ($a < $b) {
  print('$a < $b is true.'."
");
} else {
  print('$a < $b is false.'."
");
}
?>


This script will print:
Code:
$a > $b is true. $a == $b is false. $a < $b is false
  #2  
Old 14-Nov-2015, 07:30
ahmadabbas ahmadabbas is offline
Account Disabled
 
Join Date: Nov 2015
Posts: 6
ahmadabbas is an unknown quantity at this point

Re: How To Compare Two Strings with Comparison Operators in PHP?


PHP Code:

<?php 
$a = "PHP is a scripting language.";
 $b = "PHP is a general-purpose language."; 
if ($a > $b) { print('$a > $b is true.'." ");
 }
 else { print('$a > $b is false.'." "); 
}
 if ($a == $b) { print('$a == $b is true.'." ");
 }
 else { print('$a == $b is false.'." "); 
}
 if ($a < $b) { print('$a < $b is true.'." "); 
}
 else { print('$a < $b is false.'." "); 
}
?>

  #3  
Old 03-Apr-2016, 23:14
williamjohn williamjohn is offline
Junior Member
 
Join Date: Feb 2016
Posts: 47
williamjohn has a little shameless behaviour in the past

Re: How To Compare Two Strings with Comparison Operators in PHP?


using strcmp is the command used to compare to results.
  #4  
Old 03-May-2017, 02:11
honextechs honextechs is offline
New Member
 
Join Date: Apr 2017
Posts: 1
honextechs can only hope to improve

Re: How To Compare Two Strings with Comparison Operators in PHP?


Thank You your code is simple and clear
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
uisng php to display php dopee MySQL / PHP Forum 6 14-May-2004 18:40
php software dopee MySQL / PHP Forum 0 04-May-2004 11:26
How do you compare two strings? soccer022483 C++ Forum 9 22-Mar-2004 15:45
PHP in HTML jrobbio Web Design Forum 4 24-Jul-2003 06:05
All the big PHP script collections that matter jrobbio MySQL / PHP Forum 5 06-Jun-2003 16:14

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:30.


vBulletin, Copyright © 2000 - 2017, Jelsoft Enterprises Ltd.