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