I have a problem. I am using mod_rewrite to rename my URLS
Everything is working correctly until I reformatted my URLS so that spaces include - instead of %20.
site.com/page.php?country=abc®ion=d e f&city=gh i
site.com/abc/d-e-f/gh-i/
Currently I am doing this
if (isset($_GET['country'])) {$country = str_replace('-', ' ', $_GET['country']);}
if (isset($_GET['city'])) {$city = str_replace('-', ' ', $_GET['city']);}
if (isset($_GET['region'])) {$region = str_replace('-', ' ', $_GET['region']);}
I then convert back to normal when querying the database for example:
str_replace(' ', '-', $_GET['city'])
However this has created a problem as some cities use both a space AND a -. Saint-andre reunion island.
Initially I thought about running the original SQL query and if 0 results are returned, str_replacing spaces with - before running the query again. However this will only fix it if the city contains ONLY - and 0 space eg Saint-andre.
$sql2 = "SELECT `name`, FROM `list` WHERE country = '$regionCode[0]' AND admin1 = '$regionCode[1]' AND admin2 = '$regionCode[2]' AND city = '$city' ORDER BY 'moddate'";
What is the best way to handle this? Should I use double dashes instead and handle this differently? EG Saint--andre-reunion-island or is there a better way?
Thanks
Decided to go with the double dash option and created a function. I still welcome any other suggestions if there is a better option :)
Code that I am using below.
// URL Database conversion class
function QueryConversion($url) {
$url = str_replace('--', '*', $url);
$url = str_replace('-', ' ', $url);
$url = str_replace('*', '-', $url);
return $url;
}
// URL conversion class
function URLconversion($url) {
$url = str_replace('-', '--', $url);
$url = str_replace(' ', '-', $url);
return $url;
}
if (isset($_GET['country'])) {$country = QueryConversion($_GET['country']);}
if (isset($_GET['region'])) {$region = QueryConversion($_GET['region']);}
if (isset($_GET['city'])) {$city = QueryConversion($_GET['city']);}