Here's a function I've been using that I've put together from various threads around the net that removes everything, all tags and leaves you with a perfect phrase. Does anyone know how to modify this script to allow periods (.) ? In other words, leave everything 'as is' but leave the periods alone or other punctuation like and ! or a comma? let me know.
function stripAlpha( $item )
{
$search = array(
'@<script[^>]*?>.*?</script>@si' // Strip out javascript
,'@<style[^>]*?>.*?</style>@siU' // Strip style tags properly
,'@<[\/\!]*?[^<>]*?>@si' // Strip out HTML tags
,'@<![\s\S]*?–[ \t\n\r]*>@' // Strip multi-line comments including CDATA
,'/\s{2,}/'
,'/(\s){2,}/'
);
$pattern = array(
'#[^a-zA-Z ]#' // Non alpha characters
,'/\s+/' // More than one whitespace
);
$replace = array(
''
,' '
);
$item = preg_replace( $search, '', html_entity_decode( $item ) );
$item = trim( preg_replace( $pattern, $replace, strip_tags( $item ) ) );
return $item;
}