gamefreak13 Posted May 22, 2008 Share Posted May 22, 2008 Why does this work, but switching it around doesn't? <? $string = "I got the earth in my hands"; if(stristr($string, "earth") === FALSE) { echo "earth not found"; } else { echo "earth found"; } ?> This does NOT work <? $string = "I got the earth in my hands"; if(stristr($string, "earth") === TRUE) { echo "earth found"; } else { echo "earth not found"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/106733-why-does-stristr-not-work-when-set-to-true/ Share on other sites More sharing options...
sasa Posted May 22, 2008 Share Posted May 22, 2008 function stristr returns string or false newer return true Quote Link to comment https://forums.phpfreaks.com/topic/106733-why-does-stristr-not-work-when-set-to-true/#findComment-547143 Share on other sites More sharing options...
gamefreak13 Posted May 22, 2008 Author Share Posted May 22, 2008 Ok.. cause I have a problem here. I need to do 3 elseif's... but since it doesnt return true.. I don't think I can. Maybe I'm just getting too sleepy from all this coding today (all day long). The below code works if $result['referer'] (from a mysql db) contains the stuff... but I need to do an elseif for the times that it doesnt match any of the three I have configured. Currently the ones that do not match are assigned incorrectly. For example: http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=000000 should return "Profile 000000" (and it does) http://bulletins.myspace.com/index.cfm?fuseaction=bulletin.read&authorID=000000&messageID=222222 should return "Bulletin 222222" (and it does) http://messaging.myspace.com/index.cfm?fuseaction=mail.readmessage&userID=000000&type=Inbox&messageID=555555&fed=True should return "Message 555555" (and it does) ......... however.. when the referer is something like.... http://www.myspace.com/someuser it will assign "Bulletin ######", "Message ######", or "Profile ######"... even though it shouldn't! So I need to do an elseif to say "hey, it doesnt match the three predefined matches, so return "blah". ///// CHECK TO SEE IF THE REFERER IS A PROFILE VIEW if(stristr($result['referer'], "user.viewprofile") === FALSE) { //// DO NOTHING } else { preg_match('/friendid=([^&]*)/i',$result['referer'],$output); $refererclean = "Profile ".$output[1]; } ///// CHECK TO SEE IF THE REFERER IS A BULLETIN VIEW if(stristr($result['referer'], "bulletin.read") === FALSE) { //// DO NOTHING } else { preg_match('/messageid=([^&]*)/i',$result['referer'],$output); $refererclean = "Bulletin ".$output[1]; } ///// CHECK TO SEE IF THE REFERER IS A MESSAGE VIEW if(stristr($result['referer'], "mail.readmessage") === FALSE) { //// DO NOTHING } else { preg_match('/messageid=([^&]*)/i',$result['referer'],$output); $refererclean = "Message ".$output[1]; } Quote Link to comment https://forums.phpfreaks.com/topic/106733-why-does-stristr-not-work-when-set-to-true/#findComment-547145 Share on other sites More sharing options...
sasa Posted May 22, 2008 Share Posted May 22, 2008 try <?php function my_parse($text){ $a = parse_url($text); parse_str($a['query'],$b); $b = array_change_key_case($b); switch ($b['fuseaction']){ case 'user.viewprofile': return 'Profile '.$b['friendid']; break; case 'bulletin.read': return 'Bulletin '.$b['messageid']; break; case 'mail.readmessage': return 'Message '.$b['messageid']; break; default: return 'hey, it doesnt match the three predefined matches, so return "blah".'; } print_r($b); } //$sometext = 'http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=000000'; //$sometext = 'http://bulletins.myspace.com/index.cfm?fuseaction=bulletin.read&authorID=000000&messageID=222222'; $sometext = 'http://messaging.myspace.com/index.cfm?fuseaction=mail.readmessage&userID=000000&type=Inbox&messageID=555555&fed=True'; echo my_parse($sometext); ?> Quote Link to comment https://forums.phpfreaks.com/topic/106733-why-does-stristr-not-work-when-set-to-true/#findComment-547157 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.