This code snippet shows you how to check if a string contains a specific character in PHP, or if a string contains a match from an array of word options. You may also like How to search in an array with preg_grep using php and Bootstrap search box.
PHP preg_grep Code
$Item = $_POST['item'];
$getitem = nl2br($Item);
$haystack = explode('<br />',$getitem);
$trimmed_array=array_map('trim',$haystack);
$EMS = preg_grep ('/^E(\w+)/i', $trimmed_array);
$Parcel = preg_grep ('/^C(\w+)/i', $trimmed_array);
$Registered = preg_grep ('/^R(\w+)/i', $trimmed_array);
$Traffic = preg_grep ('/^T(\w+)/i', $trimmed_array);
$court = preg_grep ('/^M(\w+)/i', $trimmed_array);