A most common problem while making dynamic URLs is that while converting spaces into dashes using PHP, the multiple consecutive spaces are converted to multiple consecutive dashes, so this effects the SEO negatively. The following code solves this problem very easily:
Convert Multiple Spaces into a Single Space using PHP
$string="A string with multiple spaces";//this is a string with multiple spaces.
$clean_string=preg_replace('/\s+/',' ',$string);//multiple spaces are now converted to a single space.
The above code converts all the multiple consecutive spaces to a single space. Problem solved 🙂