Question

if ($js_enabled == "Y") {
    $qry_string = ereg_replace("(&*)js=y", "", $QUERY_STRING);
    $js_update_link = $PHP_SELF."?".($qry_string?"$qry_string&":"")."js=n";
}
else {
    $qry_string = ereg_replace("(&*)js=n", "", $QUERY_STRING);
    $js_update_link = $PHP_SELF."?".($qry_string?"$qry_string&":"")."js=y";
}

ereg_replace is deprecated and I would like to switch this to preg_replace, but the regular expression would be different right?

How would I patch this?

Was it helpful?

Solution

if ($js_enabled == "Y") {
    $qry_string = preg_replace("/(&*)js=y/", "", $QUERY_STRING);
    $js_update_link = $PHP_SELF."?".($qry_string?"$qry_string&":"")."js=n";
}
else {
    $qry_string = preg_replace("/(&*)js=n/", "", $QUERY_STRING);
    $js_update_link = $PHP_SELF."?".($qry_string?"$qry_string&":"")."js=y";
}

preg is faster and uses a PERL-style syntax (as opposed to the old Postfix style), so you may need some slight adjustments in the expression.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top