How is it possible to remove all spaces but have a hyphen between words, especially when there are spaces at the beginning or end of the string?
For example:
" Cow jumped over the moon "
should be:
"Cow-jumped-over-the-moon"
I tried the below but I'm not sure how to get rid of the spaces without hyphens before and after the string.
$string_with_dashes = str_replace(' ','-',$string);