How to make slug removing whitespaces in php

$data = “new & item @ send to & be”; $data_slug = trim($data); //$search = array(‘/’,’\\’,’:’,’;’,’!’,’@’,’#’,’$’,’%’,’^’,’*’,'(‘,’)’,’_’,’+’,’=’,’|’,'{‘,’}’,'[‘,’]’,'”‘,”‘”,'<‘,’>’,’,’,’?’,’~’,’`’,’&’,’ ‘,’.’); $search = array(‘/’,’\\’,’:’,’;’,’!’,’@’,’#’,’$’,’%’,’^’,’*’,'(‘,’)’,’_’,’+’,’=’,’|’,'{‘,’}’,'[‘,’]’,'”‘,”‘”,'<‘,’>’,’,’,’?’,’~’,’`’,’&’,’.’); $data_slug = str_replace($search, ” “, $data_slug); $data_slug1 = preg_replace(‘/\s+/’, ‘ ‘, $data_slug); $data_slug1 = trim($data_slug1); $data_slug2 = str_replace(” “, “-“, $data_slug1); echo $data_slug2;