I've created freeform fields for users to enter personal and professional interests on their profile page. It's all working, except that I'd like to alphabetize the interests.

Example: professional interests here: http://in.formatio.us/?q=user/9 (the personal interests *are* alphabetized, because I copied them from somewhere that alphabetized them).

The code I'm using to create this area is:

 <?php if($user->profile_prof_interests != ""): ?>
<div class="fields"><b>Professional interests:</b> 
<?php
$temp_array = split("[\n,]", $user->profile_prof_interests);
sort($temp_array);
$count_total = count($temp_array);
for($counter=0; $counter<$count_total; $counter++):?>
<?php $link = each($temp_array) ?><a href="?q=/profile/profile_prof_interests/<?php print preg_replace('[\s]', '+', trim($link[value])) ?>" title="People who share this interest"><?php print $link[value] ?></a>, 
<?php endfor ?></div>
<?php endif ?>

I threw in that sort on the fifth line, and it does change the order of the items, so it's doing *something*, but it's not alphabetizing them. I think it's just sorting them by the numerical keys or something. Any ideas? I think this part PHP problem, part not understanding how Drupal stores these custom fields and their contents.

Oh, and if anyone had a quick fix to kill the comma at the end of each list, that would be great too! ;)