All pastes #2051398 Raw Edit

Miscellany

public text v1 · immutable
#2051398 ·published 2011-04-28 01:37 UTC
rendered paste body
function company_case($title) {
    $smallwordsarray = array(
    'of','a','the','and','an','or','nor','but','is','if','then','else','when',
    'at','from','by','on','off','for','in','out','over','to','into','with'
    );
  $company_abb = array('corp','inc','inc.','corp.');
  $words = explode(' ', $title);
  foreach ($words as $key => $word)
  {
if (preg_match("/((?=(\\(|\\[)|\\/).|.(?=(\\)|\\]|\\/)))/", $word) or strlen($word)<=4 and !in_array(strtolower($word),$company_abb)){
      $words[$key] = mb_strtoupper($word);}    
elseif ($key == 0 or (!in_array(strtolower($word), $smallwordsarray))){
      $words[$key] = ucwords(strtolower($word));
}    
else {
      $words[$key] = strtolower($word);
	}
  }
  // Join the words back into a string
  $newtitle = implode(' ', $words);
  return $newtitle;
}