Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This should also work, taking into account, for example, page anchors (#) and at least some of those "weird characters" you mention but don't seem worried about:</p> <pre><code>function remove_query_part($url, $term) { $query_str = parse_url($url, PHP_URL_QUERY); if ($frag = parse_url($url, PHP_URL_FRAGMENT)) { $frag = '#' . $frag; } parse_str($query_str, $query_arr); unset($query_arr[$term]); $new = '?' . http_build_query($query_arr) . $frag; return str_replace(strstr($url, '?'), $new, $url); } </code></pre> <p>Demo:</p> <pre><code>$string[] = 'http://domain.com/php/doc.php?arg1=0&amp;arg2=1&amp;arg3=0'; $string[] = 'http://domain.com/php/doc.php?arg1=0&amp;arg2=1'; $string[] = 'http://domain.com/php/doc.php?arg1=0&amp;arg2=1&amp;arg3=0#frag'; $string[] = 'http://domain.com/php/doc.php?arg1=0&amp;arg2=1&amp;arg3=0&amp;arg4=4'; $string[] = 'http://domain.com/php/doc.php'; $string[] = 'http://domain.com/php/doc.php#frag'; $string[] = 'http://example.com?arg1=question?mark&amp;arg2=equal=sign&amp;arg3=hello'; foreach ($string as $str) { echo remove_query_part($str, 'arg3') . "\n"; } </code></pre> <p>Output:</p> <pre><code>http://domain.com/php/doc.php?arg1=0&amp;arg2=1 http://domain.com/php/doc.php?arg1=0&amp;arg2=1 http://domain.com/php/doc.php?arg1=0&amp;arg2=1#frag http://domain.com/php/doc.php?arg1=0&amp;arg2=1&amp;arg4=4 http://domain.com/php/doc.php http://domain.com/php/doc.php#frag http://example.com?arg1=question%3Fmark&amp;arg2=equal%3Dsign </code></pre> <p>Tested only as shown.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload