Filter a set of bad words out of a PHP array

前端 未结 5 690
你的背包
你的背包 2021-01-16 03:42

I have a PHP array of about 20,000 names, I need to filter through it and remove any name that has the word job, freelance, or project

5条回答
  •  清酒与你
    2021-01-16 04:42

    I'd be inclined to use the array_filter function and change the regex to not match on word boundaries

    $data1 = array('Phillyfreelance' , 'PhillyWebJobs', 'web2project', 'cleanname');
    
    $cleanArray = array_filter($data1, function($w) { 
         return !preg_match('~(freelance|project|job)~i', $w); 
    });
    

提交回复
热议问题