note 27729 added to function.strcmp

From: Date: Tue, 17 Dec 2002 05:13:19 +0000
Subject: note 27729 added to function.strcmp
Groups: php.notes 
Request: Send a blank email to php-notes+get-40998@lists.php.net to get a copy of this message
I have tried the strcmp function. Pls be very carefull. The string comparison must exactly "equal". So many people had confused. I.e My program read a string from test.txt file to get the "[company name]" string. // get contents of a file into a string $filename = "test.txt"; $fd = fopen ($filename, "rb"); $contents = fread ($fd, filesize ($filename)); for($i=0;$i<strpos($contents, "]")+1;$i++) { //print $contents[$i]; //$a=trim($contents[$i]); $a=$contents[$i]; echo $a; //echo $i; } $str2="[companyname]"; // this comparison will resulted on greater (1), $result=1 //please remember $tempvariable[2] != $tempvariable (is not equal) $result = strcmp(strtolower($a),strtolower($str2)); //this comparison working properly, $result=0 //$result = strcmp(strtolower($a),strtolower($str2[12])); echo $result; if ($a==$str2[12]) //double check the equality of string { echo "read the NextLine"; } else { echo "not equal"; } //end fclose ($fd); ?> I hope the above example will help you. -- http://www.php.net/manual/en/function.strcmp.php http://master.php.net/manage/user-notes.php?action=edit+27729 http://master.php.net/manage/user-notes.php?action=delete+27729 http://master.php.net/manage/user-notes.php?action=reject+27729

« previous php.notes (#40998) next »