How can I remove ?cat= from the example 1 so it can look like example 2 using PHP.
Example 1
?cat=some-cat
Example 2
some-cat
Easy, use str_replace:
$cat = '?cat=some-cat';
$cat = str_replace('?cat=', '', $cat);
EDIT:
If you are pulling this query string through something like $_SERVER['QUERY_STRING'], then I'd opt for you to use $_GET, which is an associative array of the GET variables passed to your script, so if your query string looked like this:
?cat=some-cat&dog=some-dog
The $_GET array would look like this:
(
'cat' => 'some-cat',
'dog' => 'some-dog'
)
$cat = $_GET['cat']; //some-cat
$dog = $_GET['dog']; //some-dog
Another edit:
Say you had an associative array of query vars you wish to append onto a URL string, you'd do something like this:
$query_vars = array();
$query_vars['cat'] = 'some-cat';
$query_vars['dog'] = 'some-dog';
foreach($query_vars as $key => $value) {
$query_vars[] = $key . '=' . $value;
unset($query_vars[$key]);
}
$query_string = '?' . implode('&', $query_vars); //?cat=some-cat&dog=some-dog
?cat=?cat=some-cat, ?cat=some-cat2, ?cat=some-cat3 and so on.?cat=? If no, a simplestr_replace()will be sufficient. If yes, you will need to properly parse the string$_GET... you should probably clarify the questionstr_replace()works for you, the problem is solved; otherwise, you will need to explain what you are doing.