On a lower level, the function sanitize_title_with_dashes()
converts to lowercase, replaces spaces and non-alphanumeric characters with dashes, and urlencodes whatever you pass to it.
<?php
echo sanitize_title_with_dashes( 'This is my blog post' );
// this-is-my-blog-post