1--TEST--
2Test htmlspecialchars() function : basic functionality
3--FILE--
4<?php
5echo "*** Testing htmlspecialchars() : basic functionality ***\n";
6
7$s1 = "abc<>\"&\n";
8$s2 = "&&abc<>\"&\n";
9$s3 = "a>,\<bc<>\"&\n";
10$s4 = "a\'\'&bc<>\"&\n";
11$s5 = "&amp;&lt;\n";
12echo "Basic tests\n";
13echo "Test 1: " . htmlspecialchars ($s1);
14echo "Test 2: " . htmlspecialchars ($s2);
15echo "Test 3: " . htmlspecialchars ($s3);
16echo "Test 4: " . htmlspecialchars ($s4);
17echo "Test 5: " . htmlspecialchars ($s5);
18echo "Test 6: " . htmlspecialchars ($s1,ENT_NOQUOTES);
19echo "Test 7: " . htmlspecialchars ($s2,ENT_NOQUOTES);
20echo "Test 8: " . htmlspecialchars ($s3,ENT_NOQUOTES);
21echo "Test 9: " . htmlspecialchars ($s4,ENT_NOQUOTES);
22echo "Test 10: " . htmlspecialchars ($s5,ENT_NOQUOTES);
23echo "Test 11: " . htmlspecialchars ($s1,ENT_COMPAT);
24echo "Test 12: " . htmlspecialchars ($s2,ENT_COMPAT);
25echo "Test 13: " . htmlspecialchars ($s3,ENT_COMPAT);
26echo "Test 14: " . htmlspecialchars ($s4,ENT_COMPAT);
27echo "Test 15: " . htmlspecialchars ($s5,ENT_COMPAT);
28echo "Test 16: " . htmlspecialchars ($s1,ENT_QUOTES);
29echo "Test 17: " . htmlspecialchars ($s2,ENT_QUOTES);
30echo "Test 18: " . htmlspecialchars ($s3,ENT_QUOTES);
31echo "Test 19: " . htmlspecialchars ($s4,ENT_QUOTES);
32echo "Test 20: " . htmlspecialchars ($s5,ENT_QUOTES);
33
34echo "\nTry with char set option - specify default ISO-8859-1\n";
35echo  "Test 21: " . htmlspecialchars ($s1,ENT_NOQUOTES, "ISO-8859-1");
36echo  "Test 22: " . htmlspecialchars ($s2,ENT_COMPAT, "ISO-8859-1");
37echo  "Test 23: " . htmlspecialchars ($s3,ENT_QUOTES, "ISO-8859-1");
38echo  "Test 24: " . htmlspecialchars ($s5,ENT_QUOTES, "ISO-8859-1");
39
40echo "\nTry with double decode FALSE\n";
41$s1 = "&quot;&amp;xyz&gt;abc&quot;\n";
42$s2 = "&quot;&amp;123&lt;456&quot;\n";
43$s3 = "\"300 < 400\"\n";
44echo  "Test 25: " . htmlspecialchars ($s1,ENT_NOQUOTES, "ISO-8859-1", false);
45echo  "Test 26: " . htmlspecialchars ($s2,ENT_NOQUOTES, "ISO-8859-1", false);
46echo  "Test 27: " . htmlspecialchars ($s3,ENT_NOQUOTES, "ISO-8859-1", false);
47
48echo "\nTry with double decode TRUE\n";
49echo  "Test 28: " . htmlspecialchars ($s1, ENT_NOQUOTES, "ISO-8859-1", true);
50echo  "Test 29: " . htmlspecialchars ($s2, ENT_NOQUOTES, "ISO-8859-1", true);
51
52?>
53--EXPECT--
54*** Testing htmlspecialchars() : basic functionality ***
55Basic tests
56Test 1: abc&lt;&gt;&quot;&amp;
57Test 2: &amp;&amp;abc&lt;&gt;&quot;&amp;
58Test 3: a&gt;,\&lt;bc&lt;&gt;&quot;&amp;
59Test 4: a\'\'&amp;bc&lt;&gt;&quot;&amp;
60Test 5: &amp;amp;&amp;lt;
61Test 6: abc&lt;&gt;"&amp;
62Test 7: &amp;&amp;abc&lt;&gt;"&amp;
63Test 8: a&gt;,\&lt;bc&lt;&gt;"&amp;
64Test 9: a\'\'&amp;bc&lt;&gt;"&amp;
65Test 10: &amp;amp;&amp;lt;
66Test 11: abc&lt;&gt;&quot;&amp;
67Test 12: &amp;&amp;abc&lt;&gt;&quot;&amp;
68Test 13: a&gt;,\&lt;bc&lt;&gt;&quot;&amp;
69Test 14: a\'\'&amp;bc&lt;&gt;&quot;&amp;
70Test 15: &amp;amp;&amp;lt;
71Test 16: abc&lt;&gt;&quot;&amp;
72Test 17: &amp;&amp;abc&lt;&gt;&quot;&amp;
73Test 18: a&gt;,\&lt;bc&lt;&gt;&quot;&amp;
74Test 19: a\&#039;\&#039;&amp;bc&lt;&gt;&quot;&amp;
75Test 20: &amp;amp;&amp;lt;
76
77Try with char set option - specify default ISO-8859-1
78Test 21: abc&lt;&gt;"&amp;
79Test 22: &amp;&amp;abc&lt;&gt;&quot;&amp;
80Test 23: a&gt;,\&lt;bc&lt;&gt;&quot;&amp;
81Test 24: &amp;amp;&amp;lt;
82
83Try with double decode FALSE
84Test 25: &quot;&amp;xyz&gt;abc&quot;
85Test 26: &quot;&amp;123&lt;456&quot;
86Test 27: "300 &lt; 400"
87
88Try with double decode TRUE
89Test 28: &amp;quot;&amp;amp;xyz&amp;gt;abc&amp;quot;
90Test 29: &amp;quot;&amp;amp;123&amp;lt;456&amp;quot;
91