Gleasonator Posted July 12, 2008 Share Posted July 12, 2008 Hi all. $string = strpos("Hello, world.", "universe"); echo $string; Comes up with a blank page. Yet, when I do this I don't get the desired result. $string = strpos("Hello, world.", "universe"); if ($string = false) { $message = 'Not found in string.'; } else { $message = 'Found in string at ' . $string . ' character(s) in.'; } echo $message; According to W3C Schools, the output should be false if the string cannot be found? http://www.w3schools.com/php/php_string.asp I can't seem to get it to return as false. If I change if ($string = false) to if ($string = '') it still outputs as true... because the message that's echoed is: Found in string at character(s) in. Anyone think they can help? Thank you. Link to comment https://forums.phpfreaks.com/topic/114385-solved-strpos-output-confusing/ Share on other sites More sharing options...
vikramjeet.singla Posted July 12, 2008 Share Posted July 12, 2008 correct your code in if construct... form if ($string = false) to if ($string == false) Link to comment https://forums.phpfreaks.com/topic/114385-solved-strpos-output-confusing/#findComment-588211 Share on other sites More sharing options...
Gleasonator Posted July 12, 2008 Author Share Posted July 12, 2008 Ah, that's what it was. Should've known it would be something simple I was missing. I feel like such a n00b. Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/114385-solved-strpos-output-confusing/#findComment-588212 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.