Sanitizing strings before adding as taxonomy term I am programatically creating taxonomy terms from a JSON object. I have a simple script that iterates over the converted JSON, and creates a taxonomy hierarchy. Since these terms come from a client-generated CSV they have random spaces and characters in them I want to sanitize/normalize them before I add them using taxonomy_vocabulary_save()

I've looked at the list of drupal Sanitization Functions, but those all seem to deal with HTML/JS strings. Is there a drupal way for me to format these strings, or should I just use a PHP regex to do it?
Running the text through check_plain() will sanitize anything dangerous, giving you the same result you'd get if you were to input the same title as part of the normal 'create term' process via Drupal's UI. I'd also run it through trim() to get rid of preceding/trailing whitespace. Beyond that, yes, you might need to do some custom regex to clean up things in your data, but that's impossible to say without seeing your data.