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 {} Link to comment https://forums.phpfreaks.com/topic/197390-check/ 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 {} Link to comment https://forums.phpfreaks.com/topic/197390-check/#findComment-1036034 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 Link to comment https://forums.phpfreaks.com/topic/197390-check/#findComment-1036036 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"; } Link to comment https://forums.phpfreaks.com/topic/197390-check/#findComment-1036039 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 Link to comment https://forums.phpfreaks.com/topic/197390-check/#findComment-1036043 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.