PHP替换空间 - 期望最后

I have this code here:

$this->view->category_name = $categoryName;
$albumName = strtolower($categoryName);
$albumName = preg_replace('/[\s-]+/', '-', $albumName);

and what this does it turn my string into lowercase and replace spaces with - ...however I have a category named "Miscellaneous" my code above turns into "miscellaneous" and then "miscellaneous-" how come its doing this and how can I adjust my code so it does not add it to the end?

Just remove the last dash. Finish off your code with:

$albumName = trim($albumName, '-');