网址为http://www.test.co.uk/?set_cp_city=thecity
,通常我可以使用$_GET['set_cp_city']
,但这不起作用。也许与wordpress有关。那么我如何获得参数set_cp_city
这是我的代码
<select onChange="window.location.href=this.value">
<?php
$locations = array("London","Bristol","Manchester","Kent","Essex","Lancashire","Bedfordshire","Berkshire","Buckinghamshire","Cambridgeshire","Cheshire","Cornwall","County Durham","Cumbria","Derbyshire","Devon","Dorset","East Yorkshire","East Sussex","Gloucestershire","Hampshire","Herefordshire","Hertfordshire","Isle of Wight","Leicestershire","Lincolnshire","Merseyside","Norfolk","North Yorkshire","Northamptonshire","Northumberland","Nottinghamshire","Oxfordshire","Rutland","Shropshire","Somerset","South Yorkshire","Staffordshire","Suffolk","Surrey","Tyne and Wear","Warwickshire","West Midlands","West Sussex","West Yorkshire","Wiltshire","Worcestershire");
$current_city = $_GET['set_cp_city'];
echo "<option>$current_city</option>";
foreach($locations as $value) {
?>
<option value="http://www.test.co.uk/?set_cp_city=<?php echo $value ?>"><?php echo $value ?></option>
<?php
}
?>
</select>
答案 0 :(得分:0)
$_SERVER['QUERY_STRING']
应该包含请求的查询,您可以使用parse_str()
parse_str($_SERVER['QUERY_STRING'],$output);
print_r($output);
答案 1 :(得分:0)
在您的代码中尝试此操作
$current_city = isset($_GET['set_cp_city'])?$_GET['set_cp_city']:"";