Php 正在删除已在数组中的表单帖子

Php 正在删除已在数组中的表单帖子,php,Php,大家好,我有一个表单,我想在其中添加一个函数, 我有一个存储在数组中的文本列表 $colors = array('red','blue','green'); 以及一个带有文本输入和提交的表单。 例如,当某人自动键入$colors数组中列出的一些颜色时,这些文本将被修剪或替换为空白文本。我不知道完成这个的真正功能是什么,所以我现在请求帮助。对不起,我的英语不好,谢谢你的帮助,兄弟们 if( in_array($input, $colors)) { //get the key $k

大家好,我有一个表单,我想在其中添加一个函数, 我有一个存储在数组中的文本列表

$colors = array('red','blue','green');
以及一个带有文本输入和提交的表单。 例如,当某人自动键入$colors数组中列出的一些颜色时,这些文本将被修剪或替换为空白文本。我不知道完成这个的真正功能是什么,所以我现在请求帮助。对不起,我的英语不好,谢谢你的帮助,兄弟们

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!
}
这应该可以解决问题


干杯

这是众多方法之一:

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

你应该看看函数,它返回的是真的吗?你可以用一个空白文本替换字符串。请给我文件代码。这就是我想到的:$post=$\u post['input'];如果输入数组$post,$colors,那又怎样?这不是stackoverflow应该是什么,请告诉我们您尝试了什么,以及在哪里发现了问题,以便我们可以提供帮助