Skip to content

Commit 34f90a6

Browse files
Modified the examples for mb_convert_kana, mb_detect_encoding, mb_encode_numericentity (#4510)
1 parent 2417d61 commit 34f90a6

File tree

3 files changed

+61
-31
lines changed

3 files changed

+61
-31
lines changed

reference/mbstring/functions/mb-convert-kana.xml

+15-10
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,28 @@
200200

201201
<refsect1 role="examples">
202202
&reftitle.examples;
203-
<para>
204-
<example>
205-
<title><function>mb_convert_kana</function> example</title>
206-
<programlisting role="php">
203+
<example>
204+
<title><function>mb_convert_kana</function> example</title>
205+
<programlisting role="php">
207206
<![CDATA[
208207
<?php
209-
/* Convert all "kana" to "zen-kaku" "kata-kana" */
210-
$str = mb_convert_kana($str, "KVC");
208+
/* Convert all "han-kaku" "kata-kana" to "zen-kaku" "hira-gana" */
209+
echo mb_convert_kana('ヤマダ ハナコ', "HV") . "\n";
211210
212211
/* Convert "han-kaku" "kata-kana" to "zen-kaku" "kata-kana"
213212
and "zen-kaku" alphanumeric to "han-kaku" */
214-
$str = mb_convert_kana($str, "KVa");
213+
echo mb_convert_kana('コウザバンゴウ 0123456', "KVa") . "\n";
215214
?>
216215
]]>
217-
</programlisting>
218-
</example>
219-
</para>
216+
</programlisting>
217+
&example.outputs;
218+
<screen>
219+
<![CDATA[
220+
やまだ はなこ
221+
コウザバンゴウ 0123456
222+
]]>
223+
</screen>
224+
</example>
220225
</refsect1>
221226

222227
</refentry>

reference/mbstring/functions/mb-detect-encoding.xml

+27-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
bytes form a valid string. If the input string contains such a sequence, that
3030
encoding will be rejected, and the next encoding checked.
3131
</para>
32+
33+
<warning>
34+
<title>The result is not accurate</title>
35+
<para>
36+
The name of this function is misleading, it performs "guessing" rather than "detection".
37+
</para>
38+
<para>
39+
The guesses are far from accurate, and therefore you cannot use this function to accurately
40+
detect the correct character encoding.
41+
</para>
42+
</warning>
3243
</refsect1>
3344

3445
<refsect1 role="parameters">
@@ -121,25 +132,37 @@
121132
<programlisting role="php">
122133
<![CDATA[
123134
<?php
135+
136+
$str = "\x95\xB6\x8E\x9A\x83\x52\x81\x5B\x83\x68";
137+
124138
// Detect character encoding with current detect_order
125-
echo mb_detect_encoding($str);
139+
var_dump(mb_detect_encoding($str));
126140
127141
// "auto" is expanded according to mbstring.language
128-
echo mb_detect_encoding($str, "auto");
142+
var_dump(mb_detect_encoding($str, "auto"));
129143
130144
// Specify "encodings" parameter by list separated by comma
131-
echo mb_detect_encoding($str, "JIS, eucjp-win, sjis-win");
145+
var_dump(mb_detect_encoding($str, "JIS, eucjp-win, sjis-win"));
132146
133147
// Use array to specify "encodings" parameter
134148
$encodings = [
135149
"ASCII",
136150
"JIS",
137151
"EUC-JP"
138152
];
139-
echo mb_detect_encoding($str, $encodings);
153+
var_dump(mb_detect_encoding($str, $encodings));
140154
?>
141155
]]>
142156
</programlisting>
157+
&example.outputs;
158+
<screen>
159+
<![CDATA[
160+
string(5) "ASCII"
161+
string(5) "ASCII"
162+
string(8) "SJIS-win"
163+
string(5) "ASCII"
164+
]]>
165+
</screen>
143166
</example>
144167
</para>
145168
<para>

reference/mbstring/functions/mb-encode-numericentity.xml

+19-17
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,29 @@ $convmap = array (
130130
<programlisting role="php">
131131
<![CDATA[
132132
<?php
133-
/* Convert Left side of ISO-8859-1 to HTML numeric character reference */
134-
$convmap = array(0x80, 0xff, 0, 0xff);
135-
$str = mb_encode_numericentity($str, $convmap, "ISO-8859-1");
136133
137-
/* Convert user defined SJIS-win code in block 95-104 to numeric
138-
string reference */
139-
$convmap = array(
140-
0xe000, 0xe03e, 0x1040, 0xffff,
141-
0xe03f, 0xe0bb, 0x1041, 0xffff,
142-
0xe0bc, 0xe0fa, 0x1084, 0xffff,
143-
0xe0fb, 0xe177, 0x1085, 0xffff,
144-
0xe178, 0xe1b6, 0x10c8, 0xffff,
145-
0xe1b7, 0xe233, 0x10c9, 0xffff,
146-
0xe234, 0xe272, 0x110c, 0xffff,
147-
0xe273, 0xe2ef, 0x110d, 0xffff,
148-
0xe2f0, 0xe32e, 0x1150, 0xffff,
149-
0xe32f, 0xe3ab, 0x1151, 0xffff );
150-
$str = mb_encode_numericentity($str, $convmap, "sjis-win");
134+
$str = "aAæÆあア𩸽";
135+
136+
/* Convert all UTF8 characters up to 4 bytes to HTML numeric character reference */
137+
$convmap = [0, 0x1FFFFF, 0, 0x10FFFF];
138+
var_dump(mb_encode_numericentity($str, $convmap, "utf8"));
139+
140+
/* Converts only 2-byte and 4-byte UTF8 characters to HTML numeric character reference */
141+
$convmap = [
142+
0x80, 0x7FF, 0, 0x10FFFF,
143+
0x10000, 0x1FFFFF, 0, 0x10FFFF,
144+
];
145+
var_dump(mb_encode_numericentity($str, $convmap, "utf8"));
151146
?>
152147
]]>
153148
</programlisting>
149+
&example.outputs;
150+
<screen>
151+
<![CDATA[
152+
string(46) "&#97;&#65;&#230;&#198;&#12354;&#12450;&#40509;"
153+
string(28) "aA&#230;&#198;あア&#40509;"
154+
]]>
155+
</screen>
154156
</example>
155157
</para>
156158
</refsect1>

0 commit comments

Comments
 (0)