<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.url.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.parse-url.php',
    1 => 'parse_url',
    2 => 'Parse a URL and return its components',
  ),
  'up' => 
  array (
    0 => 'ref.url.php',
    1 => 'URL Функції',
  ),
  'prev' => 
  array (
    0 => 'function.http-build-query.php',
    1 => 'http_build_query',
  ),
  'next' => 
  array (
    0 => 'function.rawurldecode.php',
    1 => 'rawurldecode',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/url/functions/parse-url.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.parse-url" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">parse_url</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">parse_url</span> &mdash; <span class="dc-title">Parse a URL and return its components</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.parse-url-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>parse_url</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$url</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$component</code><span class="initializer"> = -1</span></span>): <span class="type"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   This function parses a URL and returns an associative array containing any
   of the various components of the URL that are present.
   The values of the array elements are <em>not</em> URL decoded.
  </p>
  <p class="para">
   This function is <strong>not</strong> meant to validate
   the given URL, it only breaks it up into the parts listed below. Partial and invalid
   URLs are also accepted, <span class="function"><strong>parse_url()</strong></span> tries its best to
   parse them correctly.
  </p>
  <div class="caution"><strong class="caution">Застереження</strong>
   <p class="para">
    This function may not give correct results for relative or invalid URLs,
    and the results may not even match common behavior of HTTP clients.
    If URLs from untrusted input need to be parsed, extra validation is
    required, e.g. by using <span class="function"><a href="function.filter-var.php" class="function">filter_var()</a></span> with the
    <strong><code><a href="filter.constants.php#constant.filter-validate-url">FILTER_VALIDATE_URL</a></code></strong> filter.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.parse-url-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">url</code></dt>
     <dd>
      <p class="para">
       The URL to parse.
      </p>
     </dd>
    
   </dl>
   <dl>
    
     <dt><code class="parameter">component</code></dt>
     <dd>
      <p class="para">
       Specify one of <strong><code><a href="url.constants.php#constant.php-url-scheme">PHP_URL_SCHEME</a></code></strong>,
       <strong><code><a href="url.constants.php#constant.php-url-host">PHP_URL_HOST</a></code></strong>, <strong><code><a href="url.constants.php#constant.php-url-port">PHP_URL_PORT</a></code></strong>,
       <strong><code><a href="url.constants.php#constant.php-url-user">PHP_URL_USER</a></code></strong>, <strong><code><a href="url.constants.php#constant.php-url-pass">PHP_URL_PASS</a></code></strong>,
       <strong><code><a href="url.constants.php#constant.php-url-path">PHP_URL_PATH</a></code></strong>, <strong><code><a href="url.constants.php#constant.php-url-query">PHP_URL_QUERY</a></code></strong>
       or <strong><code><a href="url.constants.php#constant.php-url-fragment">PHP_URL_FRAGMENT</a></code></strong> to retrieve just a specific
       URL component as a <span class="type"><a href="language.types.string.php" class="type string">string</a></span> (except when
       <strong><code><a href="url.constants.php#constant.php-url-port">PHP_URL_PORT</a></code></strong> is given, in which case the return
       value will be an <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>).
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.parse-url-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   On seriously malformed URLs, <span class="function"><strong>parse_url()</strong></span> may return
   <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
  <p class="para">
   If the <code class="parameter">component</code> parameter is omitted, an
   associative <span class="type"><a href="language.types.array.php" class="type array">array</a></span> is returned. At least one element will be
   present within the array. Potential keys within this array are:
   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      <var class="varname">scheme</var> - e.g. <code class="literal">http</code>
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <var class="varname">host</var> 
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <var class="varname">port</var>
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <var class="varname">user</var>
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <var class="varname">pass</var>
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <var class="varname">path</var>
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <var class="varname">query</var> - after the question mark <code class="literal">?</code>
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <var class="varname">fragment</var> - after the hashmark <code class="literal">#</code>
     </span>
    </li>
   </ul>
  </p>
  <p class="para">
   If the <code class="parameter">component</code> parameter is specified,
   <span class="function"><strong>parse_url()</strong></span> returns a <span class="type"><a href="language.types.string.php" class="type string">string</a></span> (or an
   <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>, in the case of <strong><code><a href="url.constants.php#constant.php-url-port">PHP_URL_PORT</a></code></strong>)
   instead of an <span class="type"><a href="language.types.array.php" class="type array">array</a></span>. If the requested component doesn&#039;t exist
   within the given URL, <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> will be returned.
   As of PHP 8.0.0, <span class="function"><strong>parse_url()</strong></span> distinguishes absent and empty
   queries and fragments:
  </p>
  <p class="para">
   <div class="informalexample">
    <div class="example-contents screen">
<div class="returnvaluescode"><pre class="returnvaluescode">http://example.com/foo → query = null, fragment = null
http://example.com/foo? → query = &quot;&quot;,   fragment = null
http://example.com/foo# → query = null, fragment = &quot;&quot;
http://example.com/foo?# → query = &quot;&quot;,   fragment = &quot;&quot;</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
    Previously all cases resulted in query and fragment being <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
  </p>
  <p class="para">
   Note that control characters (cf. <span class="function"><a href="function.ctype-cntrl.php" class="function">ctype_cntrl()</a></span>) in the
   components are replaced with underscores (<code class="literal">_</code>).
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.parse-url-changelog">
  <h3 class="title">Журнал змін</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Версія</th>
      <th>Опис</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <span class="function"><strong>parse_url()</strong></span> will now distinguish absent and empty queries
       and fragments.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.parse-url-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 A <span class="function"><strong>parse_url()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$url </span><span style="color: #007700">= </span><span style="color: #DD0000">'http://username:password@hostname:9090/path?arg=value#anchor'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">parse_url</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">parse_url</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_URL_SCHEME</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">parse_url</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_URL_USER</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">parse_url</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_URL_PASS</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">parse_url</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_URL_HOST</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">parse_url</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_URL_PORT</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">parse_url</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_URL_PATH</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">parse_url</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_URL_QUERY</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">parse_url</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_URL_FRAGMENT</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">array(8) {
  [&quot;scheme&quot;]=&gt;
  string(4) &quot;http&quot;
  [&quot;host&quot;]=&gt;
  string(8) &quot;hostname&quot;
  [&quot;port&quot;]=&gt;
  int(9090)
  [&quot;user&quot;]=&gt;
  string(8) &quot;username&quot;
  [&quot;pass&quot;]=&gt;
  string(8) &quot;password&quot;
  [&quot;path&quot;]=&gt;
  string(5) &quot;/path&quot;
  [&quot;query&quot;]=&gt;
  string(9) &quot;arg=value&quot;
  [&quot;fragment&quot;]=&gt;
  string(6) &quot;anchor&quot;
}
string(4) &quot;http&quot;
string(8) &quot;username&quot;
string(8) &quot;password&quot;
string(8) &quot;hostname&quot;
int(9090)
string(5) &quot;/path&quot;
string(9) &quot;arg=value&quot;
string(6) &quot;anchor&quot;</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Приклад #2 A <span class="function"><strong>parse_url()</strong></span> example with missing scheme</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$url </span><span style="color: #007700">= </span><span style="color: #DD0000">'//www.example.com/path?googleguy=googley'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Prior to 5.4.7 this would show the path as "//www.example.com/path"<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">parse_url</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">array(3) {
  [&quot;host&quot;]=&gt;
  string(15) &quot;www.example.com&quot;
  [&quot;path&quot;]=&gt;
  string(5) &quot;/path&quot;
  [&quot;query&quot;]=&gt;
  string(17) &quot;googleguy=googley&quot;
}</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.parse-url-notes">
  <h3 class="title">Примітки</h3>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="para">
    This function is intended specifically for the purpose of parsing URLs
    and not URIs. However, to comply with PHP&#039;s backwards compatibility
    requirements it makes an exception for the <code class="literal">file://</code> scheme where triple
    slashes (<code class="literal">file:///...</code>) are allowed. For any other scheme this is invalid.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.parse-url-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.pathinfo.php" class="function" rel="rdfs-seeAlso">pathinfo()</a> - Returns information about a file path</span></li>
    <li><span class="function"><a href="function.parse-str.php" class="function" rel="rdfs-seeAlso">parse_str()</a> - Parse a string as a URL query string</span></li>
    <li><span class="function"><a href="function.http-build-query.php" class="function" rel="rdfs-seeAlso">http_build_query()</a> - Generate URL-encoded query string</span></li>
    <li><span class="function"><a href="function.dirname.php" class="function" rel="rdfs-seeAlso">dirname()</a> - Returns a parent directory's path</span></li>
    <li><span class="function"><a href="function.basename.php" class="function" rel="rdfs-seeAlso">basename()</a> - Повертає останній компонент рядка шляху</span></li>
    <li><a href="https://datatracker.ietf.org/doc/html/rfc3986" class="link external">&raquo;&nbsp;RFC 3986</a></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>