coenster Posted April 15, 2015 Share Posted April 15, 2015 I have the following code, my bad if it is not in correct format... still learning. <?php $string = file_get_contents('/path/to/file'); $found = 'found'; if($string == $found){ echo "string match"; } else { echo "string does not match found"; } echo "<br>"; echo "value of string: $string"; echo "<br>"; echo "value of found: $found"; ?> The output of that says: "string does not match found". and the value for $string and $found is the same. If the value of $string and $found are not the same it still says:"string does not match found". Am I missing something or am I going nuts... Please let me know what is wrong with my code.Thanks in advance Link to comment https://forums.phpfreaks.com/topic/295597-check-if-two-strings-match-not-working/ Share on other sites More sharing options...
dodgeitorelse3 Posted April 15, 2015 Share Posted April 15, 2015 check your path to the file. I used your code with my path and got <?php $string = file_get_contents('found.txt'); $found = 'found'; if($string == $found){ echo "string match"; } else { echo "string does not match found"; } echo "<br>"; echo "value of string: $string"; echo "<br>"; echo "value of found: $found"; ?> and displays string match value of string: found value of found: found Link to comment https://forums.phpfreaks.com/topic/295597-check-if-two-strings-match-not-working/#findComment-1509143 Share on other sites More sharing options...
Psycho Posted April 16, 2015 Share Posted April 16, 2015 Why do you "think" they match? Are there any white-space characters (e.g. spaces, tabs, etc.) in the file you are reading? You need to verify EXACTLY what those variables contain - echoing to the page isn't going to work Run this and you will see why PHP doesn't consider those values the same $string = file_get_contents('/path/to/file'); $found = 'found'; if($string == $found) { echo "string match"; } else { echo "string does not match found"; } echo "<br><br>String var: "; var_dump($string); echo "<br><br>Found var: "; var_dump($found); Link to comment https://forums.phpfreaks.com/topic/295597-check-if-two-strings-match-not-working/#findComment-1509147 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.