c_pattle Posted October 12, 2010 Share Posted October 12, 2010 I was wondering if it is possible to check the content for a variable for a certain work. For example say a variable called "$variable1" was equal to "one, two, three, four, five". How can I check to see if the variable contain the word "four"? Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/215732-check-a-variable-for-a-word/ Share on other sites More sharing options...
litebearer Posted October 12, 2010 Share Posted October 12, 2010 Might check... http://www.w3schools.com/php/func_string_stripos.asp Link to comment https://forums.phpfreaks.com/topic/215732-check-a-variable-for-a-word/#findComment-1121609 Share on other sites More sharing options...
Oziam Posted October 12, 2010 Share Posted October 12, 2010 $string = 'four'; $variable1 = array("one","two","three","four","five"); echo in_array($string, $variable1) ? 'TRUE' : 'FALSE'; or if(in_array($string, $variable1)){ echo 'TRUE'; // do something } else{ echo 'FALSE'; // do something else } Link to comment https://forums.phpfreaks.com/topic/215732-check-a-variable-for-a-word/#findComment-1121612 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.