tags:

views:

132

answers:

1

example: -this--is---a-test--

what I want: this-is-a-test

thanks for any answers! :)

+3  A: 

I would use a combination of preg_replace and trim:

trim(preg_replace('/-+/', '-', $str), '-')

The preg_replace call removes multiple dashes and trim removes the leading and trailing dashes.

Gumbo