title: Removing special characters and space from string
body: <p>I have to stored posts to database. I want to store post title as post url, so that I need to remove special characters and spaces. I have done that. Everything is working fine but when I give space at last of the string it shows hyphen at last as follows.<br>
  Ex abcd_<br>
  I just want to remove last hyphen if there is a space.<br>
  I have tried so far as follows -  </p>
  
  <pre><code>function clean($post_name) {
                 $post_name = str_replace(' ', '-', $post_name); 
                 return preg_replace('/[^A-Za-z0-9\-]/', '', $post_name);
              }
              $post_url=clean($post_name);  
  </code></pre>
  
  <p>How is this possible?<br>
  Thanks. </p>