获取网址的具体参数
网址为http://www.test.co.uk/?set_cp_city=thecity
,通常我可以使用$_GET['set_cp_city']
但这不起作用。也许与wordpress有关。那么,如何获得价值参数set_cp_city
获取网址的具体参数
Here'ss我的代码
<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>
$_SERVER['QUERY_STRING']
应包含请求的查询,并且可以使用parse_str()
它
parse_str($_SERVER['QUERY_STRING'],$output);
print_r($output);
什么是$输出?我试过这个,结果是'1' – user892134 2014-11-06 11:12:20
试图回显$ _SERVER ['QUERY_STRING'],看看它是否包含你的参数 – dynamic 2014-11-06 11:13:42
兄弟我想你需要设置值'$ data = parse_url('url')'。该语法用于'parse_str('query_string',$ return_Value)'。但无论如何,我不知道这是否仍然有效,很奇怪,'$ _GET' aint workin – Ghost 2014-11-06 11:17:56
试这在你的代码
$current_city = isset($_GET['set_cp_city'])?$_GET['set_cp_city']:"";
检查你的'.htaccess',看看是否内部存在'[QSA]'。如果不行,你可能需要在'ReWrite *'行之后添加它。 – Gary 2014-11-06 11:07:12