mirror of
https://github.com/php/doc-de.git
synced 2026-03-24 15:22:14 +01:00
197 lines
4.7 KiB
XML
197 lines
4.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 27ae0a4a16cdfc868a884c0f0dad7023b5f2709c Maintainer: sammywg Status: ready -->
|
|
<refentry xml:id="function.trim" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>trim</refname>
|
|
<refpurpose>Entfernt Whitespaces (oder andere Zeichen) am Anfang und Ende eines Strings</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>string</type><methodname>trim</methodname>
|
|
<methodparam><type>string</type><parameter>string</parameter></methodparam>
|
|
<methodparam choice="opt"><type>string</type><parameter>characters</parameter><initializer>" \n\r\t\v\x00"</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>
|
|
Die Funktion entfernt Whitespaces am Anfang und Ende von
|
|
<parameter>string</parameter> und gibt den String dann zurück. Ohne
|
|
Verwendung des zweiten Parameters entfernt <function>trim</function>
|
|
folgende Zeichen:
|
|
</simpara>
|
|
&strings.stripped.characters;
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>string</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Die zu trimmende Zeichenkette vom Typ <type>string</type>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>characters</parameter></term>
|
|
<listitem>
|
|
&strings.parameter.characters.optional;
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<simpara>
|
|
Der gekürzte String.
|
|
</simpara>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Beispiel zur Verwendung von <function>trim</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$text = "\t\tDieser Text besteht aus mehreren Wörtern :) ... ";
|
|
$binary = "\x09Beispielhafter String\x0A";
|
|
$hello = "Hallo Welt";
|
|
var_dump($text, $binary, $hello);
|
|
|
|
print "\n";
|
|
|
|
$trimmed = trim($text);
|
|
var_dump($trimmed);
|
|
|
|
$trimmed = trim($text, " \t.");
|
|
var_dump($trimmed);
|
|
|
|
$trimmed = trim($hello, "Htla");
|
|
var_dump($trimmed);
|
|
|
|
$trimmed = trim($hello, 'HtWr');
|
|
var_dump($trimmed);
|
|
|
|
// Trimmen der ASCII-Steuerzeichen an Anfang und Ende von $binary
|
|
// (inklusive der Zeichen von ASCII 0 bis 31)
|
|
$clean = trim($binary, "\x00..\x1F");
|
|
var_dump($clean);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
string(51) " Dieser Text besteht aus mehreren Wörtern :) ... "
|
|
string(23) " Beispielhafter String
|
|
"
|
|
string(10) "Hallo Welt"
|
|
|
|
string(47) "Dieser Text besteht aus mehreren Wörtern :) ..."
|
|
string(43) "Dieser Text besteht aus mehreren Wörtern :)"
|
|
string(4) "o We"
|
|
string(8) "allo Wel"
|
|
string(21) "Beispeilhafter String"
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Trimmen von Array-Werten mittels <function>trim</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
function trim_value(&$value)
|
|
{
|
|
$value = trim($value);
|
|
}
|
|
|
|
$fruechte = array('Apfel','Banane ', ' Preiselbeere ');
|
|
var_dump($fruechte);
|
|
|
|
array_walk($fruechte, 'trim_value');
|
|
var_dump($fruechte);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
array(3) {
|
|
[0]=>
|
|
string(5) "Apfel"
|
|
[1]=>
|
|
string(7) "Banane "
|
|
[2]=>
|
|
string(11) " Preiselbeere "
|
|
}
|
|
array(3) {
|
|
[0]=>
|
|
string(5) "Apfel"
|
|
[1]=>
|
|
string(6) "Banane"
|
|
[2]=>
|
|
string(9) "Preiselbeere"
|
|
}
|
|
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<note>
|
|
<title>Mögliche Überraschungen: Entfernung mittlerer Zeichen</title>
|
|
<para>
|
|
Weil <function>trim</function> Zeichen vom Anfang und Ende einer
|
|
Zeichenkette (<type>string</type>) entfernt, kann es verwirrend sein, wenn
|
|
Zeichen aus der Mitte gelöscht (oder nicht) werden. <literal>trim('abc',
|
|
'bad')</literal> entfernt 'a' und 'b', weil es 'a' entfernt, verschiebt
|
|
daher 'b' an den Anfang um ebenfalls entfernt zu werden. Daher
|
|
"funktioniert" es, <literal>trim('abc', 'b')</literal> dagegen scheinbar
|
|
nicht.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<simplelist>
|
|
<member><function>ltrim</function></member>
|
|
<member><function>rtrim</function></member>
|
|
<member><function>str_replace</function></member>
|
|
</simplelist>
|
|
</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
|
|
-->
|