-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathtrim.xml
More file actions
196 lines (177 loc) · 4.74 KB
/
trim.xml
File metadata and controls
196 lines (177 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?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
-->