I've tried using rawurlencode and urlencode, both give me "&" and the other "+".
What i'm asking is, is there a PHP function that puts "-" in between words, like on Stack Overflow?
Thanks
I've tried using rawurlencode and urlencode, both give me "&" and the other "+".
What i'm asking is, is there a PHP function that puts "-" in between words, like on Stack Overflow?
Thanks
On
rawurlencode and urlencode are for making URL's the correct format. If you want to replace spaces for dashes you need to use str_replace:
str_replace(" ", "-", $url);
On
If you just want to replace a class of characters with another, use str_replace
For example:
$newURL = str_replace(" ", "-", $oldURL);
would do what you want
urlencode is a very specific set of character replacements, which follow the standard for url encoding.
On
Okay, as mentioned url_encode is independent from making URLs from text ie to make them SEO-friendly. Usually this is called slugify an url. I guess this is generally what you're looking for, right?
Here is an example of such a method http://sourcecookbook.com/en/recipes/8/function-to-slugify-strings-in-php
If thats all you're trying to do, you could just use:
And then use
urlencodeto encode it after that. E.G.:EDIT
And according to the PHP manual, it replaces
all non-alphanumeric characters except -_. with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.