質問

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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top