How to specific character to start string to create array using php

0

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.

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);