Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

How to search in an array with preg_grep using php

by
Category:php
php
How to search in an array with preg_grep using php

The PHP function, preg_grep, is used to search an array for specific patterns and then return a new array based on that filtering follow below code with string to array and array to search specifc word(character). You may also like PHP array_search() Function and How to search record in mysql codeigniter.

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

0 Comments


Html code work in comment box


Related Post