title: How to remove the querystring and get only the URL?
body: <p>I'm using PHP to build the URL of the current page. Sometimes, URLs in the form of</p>
  <pre><code>www.example.com/myurl.html?unwantedthngs
  </code></pre>
  <p>are requested. I want to remove the <code>?</code> and everything that follows it (querystring), such that the resulting URL becomes:</p>
  <pre><code>www.example.com/myurl.html
  </code></pre>
  <p>My current code is this:</p>
  <pre><code>&lt;?php
  function curPageURL() {
      $pageURL = 'http';
      if ($_SERVER[&quot;HTTPS&quot;] == &quot;on&quot;) {
          $pageURL .= &quot;s&quot;;
      }
      $pageURL .= &quot;://&quot;;
      if ($_SERVER[&quot;SERVER_PORT&quot;] != &quot;80&quot;) {
          $pageURL .= $_SERVER[&quot;SERVER_NAME&quot;] . &quot;:&quot; .
              $_SERVER[&quot;SERVER_PORT&quot;] . $_SERVER[&quot;REQUEST_URI&quot;];
      } else {
          $pageURL .= $_SERVER[&quot;SERVER_NAME&quot;] . $_SERVER[&quot;REQUEST_URI&quot;];
      }
      return $pageURL;
  }
  ?&gt;
  </code></pre>