I have a string for example : I am a boy

I want to show this on my url for example in this way : index.php?string=I-am-a-boy

My program : 

```
            $title = "I am a boy";

            $number_wrds = str_word_count($title);
            if($number_wrds > 1){
            $url = str_replace(' ','-',$title);
            }else{
            $url = $title;
            }

```

What if I have a string : Destination - Silicon Valley

If I implement the same logic my url will be : index.php?string=Destination---Silicon-Valley

But I want to show only 1 hyphen. 

I want to show a hyphen instead of a plus sign..

`url_encode()` will eventually insert plus symbols.. So it's not helping here.

Now if I use minus symbol then if the actual string is Destination - Silicon Valley, then the url will look like 
Destination-Silicon-Valley and not 
Destination---Silicon-Valley

Check this stackoverflow question title and the url. You will know what I am saying.

[Check this](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php)