hello guys I have a form and I want to add a function in it , I have a list of texts stored in an array
$colors = array('red','blue','green');
and a form with a text input and submit . I want for example when someone types some of the colors listed in the $colors
array automaticly those texts get trimmed or get replaced with blank text . I don't know what is the real function to finish this so I'm asking for help right now . sorry for my bad english and thanks for your help brothers.
if( in_array($input, $colors)) {
//get the key
$key = array_search($input, $colors);
$colors[$key] = "";//you can use unset($colors[$key]); if you want the entry gone!
}
That should solve the problem
Cheers
This is one of the many ways to do this:
$searchString = ""; //User search here
$colors = array('red','blue','green');
foreach($colors as &$values){
$pattern = "/". $values ."/";
$searchString = preg_replace($pattern, "", $searchString);
}
//Remove any unnecessary spaces from the result
$searchString = preg_replace('/\s+/', ' ', $searchString);
echo $searchString;