I have created this function to remove specific variables from a string
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;
}
}
I am testing with:
<?php echo remove_variable(array("productsearch_name", "productsearch_type", "productsearch_supplier"), $_SERVER["REQUEST_URI"].uri_glue()); ?>
Which is returning:
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=&
So it is not removing the variables as expected
parse_strnot a regular expressionarray_diff_key()with the array you want to remove.parse_str?