Hello, say: $explode = explode(" ", $data) I want to see if a variable is found in the data when exploded, and if found, return 1 piece of code, if no found another piece of code.
which variable? what will be condition which when satisfied indicates that variable is found? put some more details with example to help you better..
$text = 'this is a test piece of text'; $terms = explode(' ', $text); $found = false; $term = 'test'; foreach($terms as $v) { if($term == $v) { $found = true; break; } } if($found) { //Term found code here } else { //Term not found code here } PHP:
Wouldn't it be quicker to use: $search = "fox"; $string = "The quick brown fox jumped over the lazy dog."; if (stripos($string, $search) === FALSE) { echo $search . " was not found"; } else { echo $search . " was found"; } PHP: That'll work if you're looking for a specific word in a string. If you're stuck with an array, you could try: $search = "fox"; /* Just creating an array real quick */ $string = "The quick brown fox jumped over the lazy dog."; $array = explode(" ", $string); if (in_array($search, $array)) { echo "Found $search."; } else { echo "Didn't find $search"; } PHP: