faqts : Computers : Programming : Languages : PHP : Common Problems : Strings

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

16 of 27 people (59%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How do I compare two variables that have been assigned text strings to make sure they match?

Apr 28th, 2000 22:20
Jerry Yoakum, Matt Williams, unknown unknown,


I believe that this question can be best answered with an example.
========================================================================
<html>
<head>
<title>Comparing strings</title>
</head>
<body>
<h3>How to compare two variables that have been assigned text strings 
to make sure they match.</h3><p>
<?php
  $strName = "Name"; // replace "Name" with data from the name textbox
  $strPassword = "Name"; // same as above except use password textbox
  if ($strName == $strPassword) {
    echo "Your password cannot be your name.";
  } else {
    echo "Your new account is ready.";
  }
?>
</body>
</html>
========================================================================
Output:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How to compare two variables that have been assigned text strings to 
make sure they match.
Your password cannot be your name. 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Output with $strPassword = "something else":
------------------------------------------------------------------------
How to compare two variables that have been assigned text strings to 
make sure they match.
Your new account is ready.
------------------------------------------------------------------------