我已创建此函数以从字符串
中删除特定变量if(!function_exists("remove_variable")) {
function remove_variable($remove = array(), $url) {
if($url == '') {
$url = $_SERVER["REQUEST_URI"];
}
foreach($remove as $r) {
echo $r.'<br>';
$url = preg_replace('/([?&])'.$r.'=[^&]+(&|$)/','$1', $url);
echo $url.'<br><br>';
}
return $url;
}
}
我正在测试:
<?php echo remove_variable(array("productsearch_name", "productsearch_type", "productsearch_supplier"), $_SERVER["REQUEST_URI"].uri_glue()); ?>
返回:
productsearch_name
/companies/customers/pricelist?productsearch_name=&productsearch_type=Broadband%20&productsearch_supplier=&
productsearch_type
/companies/customers/pricelist?productsearch_name=&productsearch_supplier=&
productsearch_supplier
/companies/customers/pricelist?productsearch_name=&productsearch_supplier=&
/companies/customers/pricelist?productsearch_name=&productsearch_supplier=&
所以它没有按预期删除变量