radio / sentences.php /
7c9f52f 7 years ago
1 contributor
24 lines | 0.819kb
<?php
function clean_string($string)
{
	$search = array('\\','u00e9','u00e0', 'u00e8', 'u20ac', 'U00e9', 'U00e0', 'U00c9', 'U00b0', 'u2019', 'U2019', 'u00ea', 'u00ea', 'u00e2', '    U00e2', 'u00f4', 'U00f4');
	$replace = array( '', 'e', 'a', 'e', 'e', 'e', 'a', 'e', '°', "'", "'", 'e', 'e', 'a', 'a', 'o', 'o' );
	$substring = str_replace($search, $replace, $string);
	return $substring;
}

function sentence_case($string) { 
  if( !is_string($string) )
    return "";
	$sentences = preg_split('/([.?!]+)/', $string, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE); 
  $new_string = ''; 
  if( is_array($sentences)) {
  	foreach ($sentences as $key => $sentence) { 
  		$new_string .= ($key & 1) == 0? 
  		ucwords(mb_strtolower(trim($sentence))) : 
  		$sentence.' '; 
    } 
  }
	return trim($new_string); 
} 
?>