Reputation: 56
I am comparing two same string values in PHP but the result says they are not equal. here is the code
$s = $fname;
$t = $temp->get_teacher_name()." ";
echo "<br/> s = $s<br/>";
echo "<br/> t = ".$temp->get_teacher_name()."<br/>";
echo var_dump($s)."<br/>;
echo var_dump($t);
if($s == $t)
{
echo"<br/>Matching<br/>";
}
The $fname is read from a file using "fgets" and i think it has a extra space at end because of that. Here is the result.
The result says they are not equals.
Upvotes: 0
Views: 621
Reputation: 674
You can use trim() to remove whitespace from beginning and end of string.
$s = trim($fname);
$t = trim($temp->get_teacher_name());
if ($s == $t) {
echo "<br/>Matching<br/>";
}
Upvotes: 2