Skip to content

Commit 45042fe

Browse files
committed
Enable WASM for book.strings, and tweak examples
1 parent 4301234 commit 45042fe

38 files changed

+234
-163
lines changed

reference/strings/book.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
33

4-
<book xml:id="book.strings" xmlns="http://docbook.org/ns/docbook">
4+
<book xml:id="book.strings" xmlns="http://docbook.org/ns/docbook" annotations="interactive">
55
<?phpdoc extension-membership="core" ?>
66
<title>Strings</title>
77

reference/strings/functions/addcslashes.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
When you define a sequence of characters in the <parameter>characters</parameter> argument
4747
make sure that you know what characters come between the
4848
characters that you set as the start and end of the range.
49-
<informalexample>
49+
<example>
50+
<title><function>addcslashes</function> with Ranges</title>
5051
<programlisting role="php">
5152
<![CDATA[
5253
<?php
@@ -57,13 +58,14 @@ echo addcslashes('foo[ ]', 'A..z');
5758
?>
5859
]]>
5960
</programlisting>
60-
</informalexample>
61+
</example>
6162
Also, if the first character in a range has a higher ASCII value
6263
than the second character in the range, no range will be
6364
constructed. Only the start, end and period characters will be
6465
escaped. Use the <function>ord</function> function to find the
6566
ASCII value for a character.
66-
<informalexample>
67+
<example>
68+
<title><function>addcslashes</function> with Characters in Wrong Order</title>
6769
<programlisting role="php">
6870
<![CDATA[
6971
<?php
@@ -72,7 +74,7 @@ echo addcslashes("zoo['.']", 'z..A');
7274
?>
7375
]]>
7476
</programlisting>
75-
</informalexample>
77+
</example>
7678
</para>
7779
<para>
7880
Be careful if you choose to escape characters 0, a, b, f, n, r, t and
@@ -106,7 +108,9 @@ echo addcslashes("zoo['.']", 'z..A');
106108
<programlisting role="php">
107109
<![CDATA[
108110
<?php
111+
$not_escaped = "PHP isThirty\nYears Old!\tYay to the Elephant!\n";
109112
$escaped = addcslashes($not_escaped, "\0..\37!@\177..\377");
113+
echo $escaped;
110114
?>
111115
]]>
112116
</programlisting>

reference/strings/functions/addslashes.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
<para>
2626
A use case of <function>addslashes</function> is escaping the aforementioned
2727
characters in a string that is to be evaluated by PHP:
28-
<informalexample>
28+
<example>
29+
<title>Escaping Characters</title>
2930
<programlisting role="php">
3031
<![CDATA[
3132
<?php
@@ -34,7 +35,7 @@ eval("echo '" . addslashes($str) . "';");
3435
?>
3536
]]>
3637
</programlisting>
37-
</informalexample>
38+
</example>
3839
</para>
3940
<para>
4041
The <function>addslashes</function> is sometimes incorrectly used to try to prevent

reference/strings/functions/chr.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,17 @@ $bytevalue %= 256;
9494
9595
$str = "The string ends in escape: ";
9696
$str .= chr(27); /* add an escape character at the end of $str */
97+
echo $str, PHP_EOL;
9798
9899
/* Often this is more useful */
99-
100100
$str = sprintf("The string ends in escape: %c", 27);
101+
echo $str, PHP_EOL;
101102
?>
102103
]]>
103104
</programlisting>
104105
</example>
106+
</para>
107+
<para>
105108
<example>
106109
<title>Overflow behavior</title>
107110
<programlisting role="php">
@@ -126,7 +129,7 @@ aA
126129
<![CDATA[
127130
<?php
128131
$str = chr(240) . chr(159) . chr(144) . chr(152);
129-
echo $str;
132+
echo $str, PHP_EOL;
130133
?>
131134
]]>
132135
</programlisting>

reference/strings/functions/chunk-split.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@
6969
<programlisting role="php">
7070
<![CDATA[
7171
<?php
72+
$data = 'This is quite a long string, which will get broken up because the line is going to be too long after base64 encoding it.';
73+
7274
// format $data using RFC 2045 semantics
7375
$new_string = chunk_split(base64_encode($data));
76+
echo $new_string, PHP_EOL;
7477
?>
7578
]]>
7679
</programlisting>

reference/strings/functions/echo.xml

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,26 @@ echo implode(" and ", $fruits); // lemon and orange and banana
105105
// Non-string expressions are coerced to string, even if declare(strict_types=1) is used
106106
echo 6 * 7; // 42
107107
108-
// Because echo does not behave as an expression, the following code is invalid.
109-
($some_var) ? echo 'true' : echo 'false';
110-
111108
// However, the following examples will work:
112109
($some_var) ? print 'true' : print 'false'; // print is also a construct, but
113110
// it is a valid expression, returning 1,
114111
// so it may be used in this context.
115112
116113
echo $some_var ? 'true': 'false'; // evaluating the expression first and passing it to echo
117114
?>
115+
]]>
116+
</programlisting>
117+
</example>
118+
</para>
119+
<para>
120+
<example>
121+
<title><literal>echo</literal> is not an expression</title>
122+
<programlisting role="php" annotations="non-interactive">
123+
<![CDATA[
124+
<?php
125+
// Because echo does not behave as an expression, the following code is invalid.
126+
($some_var) ? echo 'true' : echo 'false';
127+
?>
118128
]]>
119129
</programlisting>
120130
</example>
@@ -134,32 +144,44 @@ echo $some_var ? 'true': 'false'; // evaluating the expression first and passing
134144
part of the expression being output, not part of the <literal>echo</literal>
135145
syntax itself.
136146

137-
<informalexample>
147+
<example>
148+
<title>Using Parentheses</title>
138149
<programlisting role="php">
139150
<![CDATA[
140151
<?php
141-
echo "hello";
152+
echo "hello", PHP_EOL;
142153
// outputs "hello"
143154
144-
echo("hello");
155+
echo("hello"), PHP_EOL;
145156
// also outputs "hello", because ("hello") is a valid expression
146157
147-
echo(1 + 2) * 3;
158+
echo(1 + 2) * 3, PHP_EOL;
148159
// outputs "9"; the parentheses cause 1+2 to be evaluated first, then 3*3
149160
// the echo statement sees the whole expression as one argument
150161
151-
echo "hello", " world";
162+
echo "hello", " world", PHP_EOL;
152163
// outputs "hello world"
153164
154-
echo("hello"), (" world");
165+
echo("hello"), (" world"), PHP_EOL;
155166
// outputs "hello world"; the parentheses are part of each expression
167+
?>
168+
]]>
169+
</programlisting>
170+
</example>
171+
</para>
156172

157-
echo("hello", " world");
173+
<para>
174+
<example>
175+
<title>Invalid Expression</title>
176+
<programlisting role="php" annotations="non-interactive">
177+
<![CDATA[
178+
<?php
179+
echo("hello", " world"), PHP_EOL;
158180
// Throws a Parse Error because ("hello", " world") is not a valid expression
159181
?>
160182
]]>
161183
</programlisting>
162-
</informalexample>
184+
</example>
163185
</para>
164186
</note>
165187

reference/strings/functions/explode.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,14 @@
127127
// Example 1
128128
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
129129
$pieces = explode(" ", $pizza);
130-
echo $pieces[0]; // piece1
131-
echo $pieces[1]; // piece2
130+
echo $pieces[0], PHP_EOL; // piece1
131+
echo $pieces[1], PHP_EOL; // piece2
132132
133133
// Example 2
134134
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
135135
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
136-
echo $user; // foo
137-
echo $pass; // *
138-
136+
echo $user, PHP_EOL; // foo
137+
echo $pass, PHP_EOL; // *
139138
?>
140139
]]>
141140
</programlisting>

reference/strings/functions/fprintf.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ if (!($fp = fopen('date.txt', 'w'))) {
7070
return;
7171
}
7272
73+
$year = 2005;
74+
$month = 5;
75+
$day = 6;
76+
7377
fprintf($fp, "%04d-%02d-%02d", $year, $month, $day);
7478
// will write the formatted ISO date to date.txt
7579
?>

reference/strings/functions/html-entity-decode.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ $a = htmlentities($orig);
166166
167167
$b = html_entity_decode($a);
168168
169-
echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now
169+
echo $a, PHP_EOL; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now
170170
171-
echo $b; // I'll "walk" the <b>dog</b> now
171+
echo $b, PHP_EOL; // I'll "walk" the <b>dog</b> now
172172
?>
173173
]]>
174174
</programlisting>

reference/strings/functions/lcfirst.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@
6969
<![CDATA[
7070
<?php
7171
$foo = 'HelloWorld';
72-
$foo = lcfirst($foo); // helloWorld
72+
echo lcfirst($foo), PHP_EOL; // helloWorld
7373
7474
$bar = 'HELLO WORLD!';
75-
$bar = lcfirst($bar); // hELLO WORLD!
76-
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!
75+
echo lcfirst($bar), PHP_EOL; // hELLO WORLD!
76+
echo lcfirst(strtoupper($bar)), PHP_EOL; // hELLO WORLD!
7777
?>
7878
]]>
7979
</programlisting>

0 commit comments

Comments
 (0)