You have a malformed querystring in your url. You should do everything in your power to correct this at its source.
If you are unable to do so, then a workaround is the best you can do.
This is not a particularly efficient method, nor a simple pattern (Pattern Demo), but it will work on your sample string.
You can leverage $_SERVER['REQUEST_URI'] or whatever you wish to capture your url, then use this preg_match() method (PHP Demo):
$url=urldecode('http://www.nearbynursinghomes.com/innerpage.php?state=CA&city=RIVERSIDE&shop=ALTA%20VISTA%20HEALTHCARE%20&%20WELLNESS%20CENTRE'); if(preg_match_all('/(?<=[?&])([^=]+)=\K[^=]+(?=&|$)/',$url,$qs)){ // key------^^^^^^^ ^^^^^-------value $array=array_combine($qs[1],$qs[0]); var_export($array); } Output:
array ( 'state' => 'CA', 'city' => 'RIVERSIDE', 'shop' => 'ALTA VISTA HEALTHCARE & WELLNESS CENTRE', ) Then you can reference those array elements when you write your MySQLi prepared statements with placeholders.
If you are happy to access the other key-value pairs with $_GET and only want to extract the shop value then this is simple/direct way:
Code: (Demo)
$url = urldecode('http://www.nearbynursinghomes.com/innerpage.php?state=CA&city=RIVERSIDE&shop=ALTA%20VISTA%20HEALTHCARE%20&%20WELLNESS%20CENTRE&page=4'); echo preg_match('~[?&]shop=\K[^=]+(?=&|$)~', $url, $out) ? $out[0] : '[fail]'; Output:
ALTA VISTA HEALTHCARE & WELLNESS CENTRE