hackalive Posted April 2, 2010 Share Posted April 2, 2010 How can I check if "<php>" exists within a string? I have tried this but is always returns false even when it should be true (something to do with UTF8 i think) $PhpTagCheck = '<PHP>'; $PhpTagCheck = strpos($contents, $PhpTagCheck); if($PhpTagCheck == true){} else {} Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted April 2, 2010 Share Posted April 2, 2010 strpos() str_pos usually doesn't return false, but a boolean value that can evaluate to false. Because of that, you should use the === operator if($PhpTagCheck === true){} else {} Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 mikesta707 thankyou for your help but $PhpTagCheck = '<PHP>'; $PhpTagCheck = strpos($contents, $PhpTagCheck); if($PhpTagCheck === true){ header("location: http://www.google.com"); } else { header("location: http://www.phpfreaks.com"); //NOT WORK } its still not working Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted April 2, 2010 Share Posted April 2, 2010 oh, sorry try if($PhpTagCheck !== false){ apparently it has trouble with === the followign works for me $contents = "some string with <PHPdd> in it"; $PhpTagCheck = '<PHP>'; $PhpTagCheck = strpos($contents, $PhpTagCheck); if($PhpTagCheck !== false ){ echo "good"; //header("location: http://www.google.com"); } else { //return "It dosn't work"; echo "bad"; } Quote Link to comment Share on other sites More sharing options...
hackalive Posted April 2, 2010 Author Share Posted April 2, 2010 mikesta707 perfect thanks a lot, much appreciated 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.