So I have the following code to remove "page=" from a string. My problem now is that I want to query through "$qs_final" to check if it contains "price_range" and if so replace it with another piece of text. The price range variable is attached to "attr=" so I can't really use a $_GET request as other information is stored within it. The price_range variable also has the layout of "price_range_20".
<?php
$querystring = explode("&",$_SERVER['QUERY_STRING']);
$qs_nos = 0;
$qs_final = "";
while(isset($querystring[$qs_nos])) {
if(!ereg("page=",$querystring[$qs_nos])) {
$qs_final .= $querystring[$qs_nos]."&";
}
$qs_nos++;
}
if (strpos($qs_final,'price_range') !== false) {
print "true";
}
?>
$new_string = str_replace($what_to_replace, $what_to_replace_it_with, $old_string);
EDIT: To replace data, you need preg_replace()
. In your case to remove "price_range" and all numbers and underscores directly after it, use this:
$new_string = preg_replace("/price_range[0-9_]+/", "", $old_string);