1--TEST--
2Test base64_decode() function : basic functionality - strict vs non-strict with non-base64 chars.
3--FILE--
4<?php
5echo "Decode 'hello world!':\n";
6$noWhiteSpace = "aGVsbG8gd29ybGQh";
7var_dump(base64_decode($noWhiteSpace));
8var_dump(base64_decode($noWhiteSpace, false));
9var_dump(base64_decode($noWhiteSpace, true));
10
11echo "\nWhitespace does not affect base64_decode, even with \$strict===true:\n";
12$withWhiteSpace = "a GVs   bG8gd2
13                        9ybGQh";
14var_dump(base64_decode($withWhiteSpace));
15var_dump(base64_decode($withWhiteSpace, false));
16var_dump(base64_decode($withWhiteSpace, true));
17
18echo "\nOther chars outside the base64 alphabet are ignored when \$strict===false, but cause failure with \$strict===true:\n";
19$badChars = $noWhiteSpace . '*';
20var_dump(base64_decode($badChars));
21var_dump(base64_decode($badChars, false));
22var_dump(base64_decode($badChars, true));
23
24echo "\nTests on long string for SIMD\n";
25$noWhiteSpace = "UEhQIGlzIGEgcG9wdWxhciBnZW5lcmFsLXB1cnBvc2Ugc2NyaXB0aW5nIGxhbmd1YWdlIHRoYXQgaXMgZXNwZWNpYWxseSBzdWl0ZWQgdG8gd2ViIGRldmVsb3BtZW50";
26var_dump(base64_decode($noWhiteSpace));
27var_dump(base64_decode($noWhiteSpace, false));
28var_dump(base64_decode($noWhiteSpace, true));
29$withWhiteSpace = "UEhQIGlzIGE gcG9wdWxhciBnZW5lcmFsLXB1cnBvc2Ugc2NyaXB0aW5nIGxhbmd1YWdl IHRoYXQga
30                        XMgZXNwZWNpYWxseSBzdWl0ZWQgdG8gd2ViIGRldmVsb3BtZW50";
31var_dump(base64_decode($withWhiteSpace));
32var_dump(base64_decode($withWhiteSpace, false));
33var_dump(base64_decode($withWhiteSpace, true));
34$badChars = $noWhiteSpace . '*';
35var_dump(base64_decode($badChars));
36var_dump(base64_decode($badChars, false));
37var_dump(base64_decode($badChars, true));
38
39echo "Done";
40?>
41--EXPECT--
42Decode 'hello world!':
43string(12) "hello world!"
44string(12) "hello world!"
45string(12) "hello world!"
46
47Whitespace does not affect base64_decode, even with $strict===true:
48string(12) "hello world!"
49string(12) "hello world!"
50string(12) "hello world!"
51
52Other chars outside the base64 alphabet are ignored when $strict===false, but cause failure with $strict===true:
53string(12) "hello world!"
54string(12) "hello world!"
55bool(false)
56
57Tests on long string for SIMD
58string(96) "PHP is a popular general-purpose scripting language that is especially suited to web development"
59string(96) "PHP is a popular general-purpose scripting language that is especially suited to web development"
60string(96) "PHP is a popular general-purpose scripting language that is especially suited to web development"
61string(96) "PHP is a popular general-purpose scripting language that is especially suited to web development"
62string(96) "PHP is a popular general-purpose scripting language that is especially suited to web development"
63string(96) "PHP is a popular general-purpose scripting language that is especially suited to web development"
64string(96) "PHP is a popular general-purpose scripting language that is especially suited to web development"
65string(96) "PHP is a popular general-purpose scripting language that is especially suited to web development"
66bool(false)
67Done
68