Convert strings to slugs

Language:: PHP Type::#type/snippet Back-end

Description:: Need to generate slugs (permalinks) that are SEO friendly? The following function takes a string as a parameter and will return a SEO friendly slug. Simple and efficient!

`1.``function`  `slug(``$str``){`
`2.``$str`  `= ``strtolower``(trim(``$str``));`
`3.``$str`  `= preg_replace(``'/[^a-z0-9-]/'``, ``'-'``, ``$str``);`
`4.``$str`  `= preg_replace(``'/-+/'``, ``"-"``, ``$str``);`
`5.``return`  `$str``;`
`6.``}`

Source: http://snipplr.com/view.php?codeview&id=2809