How do I change the capitalization formatting of my Taxonomy terms programatically? I am using taxonomy terms with the formatting where the first Letter of the phrase (if there is more than one word in the taxonomy) is capitalized, and then the others are not. So, for examples 'Cars and trucks'

In house we have made the decision to change these so that every major word is capitalized, so, 'Cars and Trucks,' excluding minor words like and, it, but, etc - basically the word list that is in the Path auto terms to exclude.

I have thousands of terms. More over, there was a point when the community contributed them so there is no consistency.

Thoughts on how to tackle this without having to edit them one by one? 

Thanks
It's fairly easy to cobble some (admittedly inefficient) code together that will convert a string to title case while ignoring certain words (you'll have to choose the words yourself though):

function _MYMODULE_custom_title_case($string, $blacklist = array()) {
  // Split the words into an array
  $words = explode(' ', $string);

  $new_words = array();
  foreach ($words as $word) {
    // If the word isn't in the blacklist, capitalise it.
    if (!in_array($word, $blacklist)) {
      $word = ucfirst($word);
    }

    $new_words[] = $word;
  }

  // Join the string back up and return it.
  return implode(' ', $new_words);
}


Then you can simply load all of the terms in your vocabulary, change the title, and save them:

$vid = 1; // Vocabulary ID
$terms = taxonomy_get_tree($vid); // Get the terms

// User the pathauto blacklist
$blacklist = variable_get('pathauto_ignore_words', array()); 
foreach ($terms as $term) {
  // Update
  $term-&gt;name = _MYMODULE_custom_title_case($term-&gt;name, $blacklist);

  // And save
  taxonomy_term_save($term);
}


I confess to not having tested that so use a bit of caution! If you've got a lot of terms you might want to split it up into batches to avoid hitting a PHP timeout.