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 Quote Link to comment Share on other sites More sharing options...
dodgeitorelse3 Posted April 15, 2015 Share Posted April 15, 2015 (edited) 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 Edited April 15, 2015 by dodgeitorelse3 Quote Link to comment 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); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.