Jump to content

Why does stristr not work when set to TRUE?


gamefreak13

Recommended Posts

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";
}

?>

Link to comment
Share on other sites

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];
}

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.