mirror of
https://github.com/php/doc-de.git
synced 2026-03-24 07:12:15 +01:00
319 lines
9.2 KiB
XML
319 lines
9.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 4266e03897e77751a6cf7d15f9556c92124d8df3 Maintainer: sammywg Status: ready -->
|
|
<!-- Reviewed: yes -->
|
|
<!-- Rev-Revision: 0254e633d2a0cf36c3b3a2ba19350019e12d3b4b Reviewer: samesch -->
|
|
<refentry xml:id="function.parse-url" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>parse_url</refname>
|
|
<refpurpose>Analysiert eine URL und gibt ihre Bestandteile zurück</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>int</type><type>string</type><type>array</type><type>null</type><type>false</type></type><methodname>parse_url</methodname>
|
|
<methodparam><type>string</type><parameter>url</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>component</parameter><initializer>-1</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Diese Funktion parst eine URL und gibt ein assoziatives Array zurück, das
|
|
die in der URL vorhandenen Komponenten enthält.
|
|
Die Werte der Array-Elemente sind <emphasis>nicht</emphasis> URL-dekodiert.
|
|
</para>
|
|
<para>
|
|
Diese Funktion ist <emphasis role="strong">nicht</emphasis> dazu gedacht,
|
|
eine gegebene URL zu validieren, sondern es gliedert eine URL in die
|
|
unten aufgeführten Bestandteile. Unvollständige und ungültige URLs werden
|
|
als Parameter akzeptiert; <function>parse_url</function> versucht, sie so
|
|
gut wie möglich korrekt zu analysieren.
|
|
</para>
|
|
<caution>
|
|
<para>
|
|
Diese Funktion gibt bei relativen oder ungültigen URLs möglicherweise
|
|
inkorrekte Ergebnisse zurück und die Ergebnisse entsprechen möglicherweise
|
|
nicht einmal dem üblichen Verhalten von HTTP-Clients. Wenn URLs von nicht
|
|
vertrauenswürdigen Eingaben ausgewertet werden müssen, ist eine
|
|
zusätzliche Überprüfung erforderlich, &zb; durch Verwendung von
|
|
<function>filter_var</function> mit dem Filter
|
|
<constant>FILTER_VALIDATE_URL</constant>.
|
|
</para>
|
|
</caution>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>url</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Die zu analysierende URL.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>component</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Geben Sie einen der folgenden Parameter an, um nur einen spezifischen
|
|
Teil der URL als <type>String</type> (außer wenn
|
|
<constant>PHP_URL_PORT</constant> angegeben wird, in diesem Fall ist
|
|
der Rückgabewert ein <type>int</type>) zu erhalten:
|
|
<constant>PHP_URL_SCHEME</constant>,
|
|
<constant>PHP_URL_HOST</constant>, <constant>PHP_URL_PORT</constant>,
|
|
<constant>PHP_URL_USER</constant>, <constant>PHP_URL_PASS</constant>,
|
|
<constant>PHP_URL_PATH</constant>, <constant>PHP_URL_QUERY</constant>
|
|
oder <constant>PHP_URL_FRAGMENT</constant>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Bei sehr fehlerhaften URLs kann <function>parse_url</function> &false;
|
|
zurückgeben.
|
|
</para>
|
|
<para>
|
|
Wird der Parameter <parameter>component</parameter> ausgelassen, wird ein
|
|
assoziatives <type>Array</type> zurückgegeben. Mindestens ein Bestandteil
|
|
liegt im Array vor. Mögliche Schlüssel in diesem Array sind:
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">scheme</varname> - &zb; <literal>http</literal>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">host</varname>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">port</varname>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">user</varname>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">pass</varname>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">path</varname>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">query</varname> - alles nach dem Fragezeichen
|
|
<literal>?</literal>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">fragment</varname> - alles nach dem Text-Anker
|
|
<literal>#</literal>
|
|
</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</para>
|
|
<para>
|
|
Ist der Parameter <parameter>component</parameter> angegeben, gibt
|
|
<function>parse_url</function> einen <type>String</type> (oder ein
|
|
<type>int</type> bei <constant>PHP_URL_PORT</constant>) anstelle eines
|
|
<type>Array</type>s zurück. Wenn die angeforderte Komponente in der
|
|
angegebenen URL nicht existiert, wird &null; zurückgegeben. Seit PHP 8.0.0
|
|
unterscheidet <function>parse_url</function> zwischen fehlenden und leeren
|
|
Abfragen und Fragmenten:
|
|
</para>
|
|
<para>
|
|
<informalexample>
|
|
<screen>
|
|
<![CDATA[
|
|
http://example.com/foo → query = null, fragment = null
|
|
http://example.com/foo? → query = "", fragment = null
|
|
http://example.com/foo# → query = null, fragment = ""
|
|
http://example.com/foo?# → query = "", fragment = ""
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
Zuvor führten alle Fälle dazu, dass Abfrage und Fragment &null; waren.
|
|
</para>
|
|
<para>
|
|
Zu beachten ist, dass Steuerzeichen (vgl. <function>ctype_cntrl</function>)
|
|
in den Komponenten durch Unterstriche (<literal>_</literal>) ersetzt werden.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.0.0</entry>
|
|
<entry>
|
|
<function>parse_url</function> unterscheidet nun zwischen fehlenden
|
|
und leeren Abfragen und Fragmenten.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ein <function>parse_url</function>-Beispiel</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$url = 'http://benutzername:passwort@hostname:9090/pfad?argument=wert#textanker';
|
|
|
|
var_dump(parse_url($url));
|
|
var_dump(parse_url($url, PHP_URL_SCHEME));
|
|
var_dump(parse_url($url, PHP_URL_USER));
|
|
var_dump(parse_url($url, PHP_URL_PASS));
|
|
var_dump(parse_url($url, PHP_URL_HOST));
|
|
var_dump(parse_url($url, PHP_URL_PORT));
|
|
var_dump(parse_url($url, PHP_URL_PATH));
|
|
var_dump(parse_url($url, PHP_URL_QUERY));
|
|
var_dump(parse_url($url, PHP_URL_FRAGMENT));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
array(8) {
|
|
["scheme"]=>
|
|
string(4) "http"
|
|
["host"]=>
|
|
string(8) "hostname"
|
|
["port"]=>
|
|
int(9090)
|
|
["user"]=>
|
|
string(12) "benutzername"
|
|
["pass"]=>
|
|
string(8) "passwort"
|
|
["path"]=>
|
|
string(5) "/pfad"
|
|
["query"]=>
|
|
string(13) "argument=wert"
|
|
["fragment"]=>
|
|
string(9) "textanker"
|
|
}
|
|
string(4) "http"
|
|
string(12) "benutzername"
|
|
string(8) "passwort"
|
|
string(8) "hostname"
|
|
int(9090)
|
|
string(5) "/pfad"
|
|
string(13) "argument=wert"
|
|
string(9) "textanker"
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Ein <function>parse_url</function>-Beispiel mit fehlendem Schema</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$url = '//www.example.com/path?googleguy=googley';
|
|
|
|
// Vor 5.4.7 wurde der Pfad als "//www.example.com/path" angezeigt
|
|
var_dump(parse_url($url));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
array(3) {
|
|
["host"]=>
|
|
string(15) "www.example.com"
|
|
["path"]=>
|
|
string(5) "/path"
|
|
["query"]=>
|
|
string(17) "googleguy=googley"
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<note>
|
|
<para>
|
|
Die Funktion ist primär dazu gedacht, URLs zu analysieren, nicht jedoch
|
|
URIs. Um jedoch die Abwärtskompatibilität von PHP zu gewährleisten, wird
|
|
für das Schema <literal>file://</literal> die Ausnahme dreier Slashes
|
|
(<literal>file:///</literal>) zugelassen. Bei allen anderen Schemata ist
|
|
diese Notierung ungültig.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>pathinfo</function></member>
|
|
<member><function>parse_str</function></member>
|
|
<member><function>http_build_query</function></member>
|
|
<member><function>dirname</function></member>
|
|
<member><function>basename</function></member>
|
|
<member><link xlink:href="&url.rfc;3986">RFC 3986</link></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|