function clean($text) {
return preg_replace(
array('/&#?[a-z0-9]{2,8};/i', '/\s+/'),
array('',' '),
str_replace(
array('’','”','—'),
array('\'','"','-'),
strip_tags($text)
)
);
}
echo clean($text);
Update :
You can refactor the code with only single preg_replace
like this:
function clean($text) {
return preg_replace(
array('/&#?[a-z0-9]{2,8};/i', '/\s+/','/’/','/”/','/—/'),
array('',' ','\'','"','-'),
strip_tags($text)
);
}