Thanks for the response, bcworkz, and for pointing me towards urlencode. I did try that, and it was definitely the right direction, but my tab ids weren’t cooperating. It did lead me towards a solution, though, which was preg_replace.
Here’s what I did:
$safename02 = preg_replace('/[\s\W]+/','-',get_cat_name($cat02));
// Strip off spaces and non-alpha-numeric
$safename02 = strtolower($safename02);
Then:
$out .= '<li><a href="#'.$safename02.'" data-toggle="tab">'.get_cat_name($cat02).'</a></li>';
And, also:
$out .= '<div class="tab-pane fade" id="'.$safename02.'">';