Search code examples
phpurlgetquery-stringurl-encoding

How to handle an un-encoded special character in a url query string?


I have a url like this:

http://www.nearbynursinghomes.com/innerpage.php?state=CA&city=RIVERSIDE&shop=ALTA%20VISTA%20HEALTHCARE%20&%20WELLNESS%20CENTRE

I'm currently using this code:

$category = $_GET["state"];
$city= $_GET["city"];
$shop= $_GET["shop"];
if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 

$start_from = ($page-1) * $results_per_page;
$sql = "SELECT *
    FROM $datatable 
    WHERE STATE='$category'
    AND CITY='$city'
    AND PROVNAME='$shop'
    ORDER BY PROVNAME ASC LIMIT $start_from, $results_per_page" ;
$rs_result = $conn->query($sql); 

However it doesn't return the proper value because of the & in the middle of the value which says shop=ALTA%20VISTA%20HEALTHCARE%20&%20WELLNESS%20CENTRE.

It just gets cut off. How would I fix this?


Solution

  • After a good nights rest i came up with this solution using the tools provided here.

    $shop= $_SERVER['REQUEST_URI'];
    $shop= explode("=", $shop,4);
    $shop= $shop[3];
    $shop= urldecode("$shop");