Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use <a href="http://php.net/manual/en/function.parse-url.php">PHP Manual - parse_url()</a> to get the parts you need.</p> <p><strong>Edit (example usage for @Navi Gamage)</strong></p> <p>You can use it like this:</p> <pre><code>&lt;?php function reconstruct_url($url){ $url_parts = parse_url($url); $constructed_url = $url_parts['scheme'] . '://' . $url_parts['host'] . $url_parts['path']; return $constructed_url; } ?&gt; </code></pre> <p><strong>Edit (second full example):</strong></p> <p>Updated function to make sure scheme will be attached and none notice msgs appear:</p> <pre><code>function reconstruct_url($url){ $url_parts = parse_url($url); $constructed_url = $url_parts['scheme'] . '://' . $url_parts['host'] . (isset($url_parts['path'])?$url_parts['path']:''); return $constructed_url; } $test = array( 'http://www.mydomian.com/myurl.html?unwan=abc', 'http://www.mydomian.com/myurl.html', 'http://www.mydomian.com', 'https://mydomian.com/myurl.html?unwan=abc&amp;ab=1' ); foreach($test as $url){ print_r(parse_url($url)); } </code></pre> <p>Will return:</p> <pre><code>Array ( [scheme] =&gt; http [host] =&gt; www.mydomian.com [path] =&gt; /myurl.html [query] =&gt; unwan=abc ) Array ( [scheme] =&gt; http [host] =&gt; www.mydomian.com [path] =&gt; /myurl.html ) Array ( [scheme] =&gt; http [host] =&gt; www.mydomian.com ) Array ( [path] =&gt; mydomian.com/myurl.html [query] =&gt; unwan=abc&amp;ab=1 ) </code></pre> <p>This is the output from passing example urls through parse_url() with no second parameter (for explanation only).</p> <p>And this is the final output after constructing url using:</p> <pre><code>foreach($test as $url){ echo reconstruct_url($url) . '&lt;br/&gt;'; } </code></pre> <p>Output:</p> <pre><code>http://www.mydomian.com/myurl.html http://www.mydomian.com/myurl.html http://www.mydomian.com https://mydomian.com/myurl.html </code></pre>
 

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