1--TEST--
2Test htmlentities() function
3--FILE--
4<?php
5/* Prototype: string htmlentities ( string $string [, int $quote_style [, string $charset]] );
6   Description: Convert all applicable characters to HTML entities
7*/
8
9/* retrieving htmlentities from the ANSI character table */
10echo "*** Retrieving htmlentities for 256 characters ***\n";
11for($i=0; $i<256; $i++)
12  var_dump( bin2hex( htmlentities("chr($i)")) );
13
14/* giving arguments as NULL */
15echo "\n*** Testing htmlentities() with NULL as first,second and third argument ***\n";
16var_dump( htmlentities("\x82\x86\x99\x9f\x80\x82\x81", ENT_QUOTES, NULL) ); /* UTF-8 assumed */
17var_dump( htmlentities("\x82\x86\x99\x9f\x80\x82\x81", ENT_NOQUOTES, NULL) ); /* UTF-8 assumed */
18var_dump( htmlentities("\x82\x86\x99\x9f\x80\x82\x81", ENT_COMPAT, NULL) ); /* UTF-8 assumed */
19
20/* giving long string to check for proper memory re-allocation */
21echo "\n*** Checking for proper memory allocation with long string ***\n";
22var_dump( htmlentities("\x82\x86\x99\x9f\x80\x82\x86\x84\x80\x89\x85\x83\x86\x84\x80\x91\x83\x91\x86\x87\x85\x86\x88\x82\x89\x92\x91\x83", ENT_QUOTES, 'cp1252'));
23
24/* giving a normal string */
25echo "\n*** Testing a normal string with htmlentities() ***\n";
26var_dump( htmlentities("<html> This is a test! </html>") );
27
28/* checking behavior of quote */
29echo "\n*** Testing htmlentites() on a quote ***\n";
30$str = "A 'quote' is <b>bold</b>";
31var_dump( htmlentities($str) );
32var_dump( htmlentities($str, ENT_QUOTES) );
33var_dump( htmlentities($str, ENT_NOQUOTES) );
34var_dump( htmlentities($str, ENT_COMPAT) );
35
36echo "Done\n";
37?>
38--EXPECT--
39*** Retrieving htmlentities for 256 characters ***
40string(12) "636872283029"
41string(12) "636872283129"
42string(12) "636872283229"
43string(12) "636872283329"
44string(12) "636872283429"
45string(12) "636872283529"
46string(12) "636872283629"
47string(12) "636872283729"
48string(12) "636872283829"
49string(12) "636872283929"
50string(14) "63687228313029"
51string(14) "63687228313129"
52string(14) "63687228313229"
53string(14) "63687228313329"
54string(14) "63687228313429"
55string(14) "63687228313529"
56string(14) "63687228313629"
57string(14) "63687228313729"
58string(14) "63687228313829"
59string(14) "63687228313929"
60string(14) "63687228323029"
61string(14) "63687228323129"
62string(14) "63687228323229"
63string(14) "63687228323329"
64string(14) "63687228323429"
65string(14) "63687228323529"
66string(14) "63687228323629"
67string(14) "63687228323729"
68string(14) "63687228323829"
69string(14) "63687228323929"
70string(14) "63687228333029"
71string(14) "63687228333129"
72string(14) "63687228333229"
73string(14) "63687228333329"
74string(14) "63687228333429"
75string(14) "63687228333529"
76string(14) "63687228333629"
77string(14) "63687228333729"
78string(14) "63687228333829"
79string(14) "63687228333929"
80string(14) "63687228343029"
81string(14) "63687228343129"
82string(14) "63687228343229"
83string(14) "63687228343329"
84string(14) "63687228343429"
85string(14) "63687228343529"
86string(14) "63687228343629"
87string(14) "63687228343729"
88string(14) "63687228343829"
89string(14) "63687228343929"
90string(14) "63687228353029"
91string(14) "63687228353129"
92string(14) "63687228353229"
93string(14) "63687228353329"
94string(14) "63687228353429"
95string(14) "63687228353529"
96string(14) "63687228353629"
97string(14) "63687228353729"
98string(14) "63687228353829"
99string(14) "63687228353929"
100string(14) "63687228363029"
101string(14) "63687228363129"
102string(14) "63687228363229"
103string(14) "63687228363329"
104string(14) "63687228363429"
105string(14) "63687228363529"
106string(14) "63687228363629"
107string(14) "63687228363729"
108string(14) "63687228363829"
109string(14) "63687228363929"
110string(14) "63687228373029"
111string(14) "63687228373129"
112string(14) "63687228373229"
113string(14) "63687228373329"
114string(14) "63687228373429"
115string(14) "63687228373529"
116string(14) "63687228373629"
117string(14) "63687228373729"
118string(14) "63687228373829"
119string(14) "63687228373929"
120string(14) "63687228383029"
121string(14) "63687228383129"
122string(14) "63687228383229"
123string(14) "63687228383329"
124string(14) "63687228383429"
125string(14) "63687228383529"
126string(14) "63687228383629"
127string(14) "63687228383729"
128string(14) "63687228383829"
129string(14) "63687228383929"
130string(14) "63687228393029"
131string(14) "63687228393129"
132string(14) "63687228393229"
133string(14) "63687228393329"
134string(14) "63687228393429"
135string(14) "63687228393529"
136string(14) "63687228393629"
137string(14) "63687228393729"
138string(14) "63687228393829"
139string(14) "63687228393929"
140string(16) "6368722831303029"
141string(16) "6368722831303129"
142string(16) "6368722831303229"
143string(16) "6368722831303329"
144string(16) "6368722831303429"
145string(16) "6368722831303529"
146string(16) "6368722831303629"
147string(16) "6368722831303729"
148string(16) "6368722831303829"
149string(16) "6368722831303929"
150string(16) "6368722831313029"
151string(16) "6368722831313129"
152string(16) "6368722831313229"
153string(16) "6368722831313329"
154string(16) "6368722831313429"
155string(16) "6368722831313529"
156string(16) "6368722831313629"
157string(16) "6368722831313729"
158string(16) "6368722831313829"
159string(16) "6368722831313929"
160string(16) "6368722831323029"
161string(16) "6368722831323129"
162string(16) "6368722831323229"
163string(16) "6368722831323329"
164string(16) "6368722831323429"
165string(16) "6368722831323529"
166string(16) "6368722831323629"
167string(16) "6368722831323729"
168string(16) "6368722831323829"
169string(16) "6368722831323929"
170string(16) "6368722831333029"
171string(16) "6368722831333129"
172string(16) "6368722831333229"
173string(16) "6368722831333329"
174string(16) "6368722831333429"
175string(16) "6368722831333529"
176string(16) "6368722831333629"
177string(16) "6368722831333729"
178string(16) "6368722831333829"
179string(16) "6368722831333929"
180string(16) "6368722831343029"
181string(16) "6368722831343129"
182string(16) "6368722831343229"
183string(16) "6368722831343329"
184string(16) "6368722831343429"
185string(16) "6368722831343529"
186string(16) "6368722831343629"
187string(16) "6368722831343729"
188string(16) "6368722831343829"
189string(16) "6368722831343929"
190string(16) "6368722831353029"
191string(16) "6368722831353129"
192string(16) "6368722831353229"
193string(16) "6368722831353329"
194string(16) "6368722831353429"
195string(16) "6368722831353529"
196string(16) "6368722831353629"
197string(16) "6368722831353729"
198string(16) "6368722831353829"
199string(16) "6368722831353929"
200string(16) "6368722831363029"
201string(16) "6368722831363129"
202string(16) "6368722831363229"
203string(16) "6368722831363329"
204string(16) "6368722831363429"
205string(16) "6368722831363529"
206string(16) "6368722831363629"
207string(16) "6368722831363729"
208string(16) "6368722831363829"
209string(16) "6368722831363929"
210string(16) "6368722831373029"
211string(16) "6368722831373129"
212string(16) "6368722831373229"
213string(16) "6368722831373329"
214string(16) "6368722831373429"
215string(16) "6368722831373529"
216string(16) "6368722831373629"
217string(16) "6368722831373729"
218string(16) "6368722831373829"
219string(16) "6368722831373929"
220string(16) "6368722831383029"
221string(16) "6368722831383129"
222string(16) "6368722831383229"
223string(16) "6368722831383329"
224string(16) "6368722831383429"
225string(16) "6368722831383529"
226string(16) "6368722831383629"
227string(16) "6368722831383729"
228string(16) "6368722831383829"
229string(16) "6368722831383929"
230string(16) "6368722831393029"
231string(16) "6368722831393129"
232string(16) "6368722831393229"
233string(16) "6368722831393329"
234string(16) "6368722831393429"
235string(16) "6368722831393529"
236string(16) "6368722831393629"
237string(16) "6368722831393729"
238string(16) "6368722831393829"
239string(16) "6368722831393929"
240string(16) "6368722832303029"
241string(16) "6368722832303129"
242string(16) "6368722832303229"
243string(16) "6368722832303329"
244string(16) "6368722832303429"
245string(16) "6368722832303529"
246string(16) "6368722832303629"
247string(16) "6368722832303729"
248string(16) "6368722832303829"
249string(16) "6368722832303929"
250string(16) "6368722832313029"
251string(16) "6368722832313129"
252string(16) "6368722832313229"
253string(16) "6368722832313329"
254string(16) "6368722832313429"
255string(16) "6368722832313529"
256string(16) "6368722832313629"
257string(16) "6368722832313729"
258string(16) "6368722832313829"
259string(16) "6368722832313929"
260string(16) "6368722832323029"
261string(16) "6368722832323129"
262string(16) "6368722832323229"
263string(16) "6368722832323329"
264string(16) "6368722832323429"
265string(16) "6368722832323529"
266string(16) "6368722832323629"
267string(16) "6368722832323729"
268string(16) "6368722832323829"
269string(16) "6368722832323929"
270string(16) "6368722832333029"
271string(16) "6368722832333129"
272string(16) "6368722832333229"
273string(16) "6368722832333329"
274string(16) "6368722832333429"
275string(16) "6368722832333529"
276string(16) "6368722832333629"
277string(16) "6368722832333729"
278string(16) "6368722832333829"
279string(16) "6368722832333929"
280string(16) "6368722832343029"
281string(16) "6368722832343129"
282string(16) "6368722832343229"
283string(16) "6368722832343329"
284string(16) "6368722832343429"
285string(16) "6368722832343529"
286string(16) "6368722832343629"
287string(16) "6368722832343729"
288string(16) "6368722832343829"
289string(16) "6368722832343929"
290string(16) "6368722832353029"
291string(16) "6368722832353129"
292string(16) "6368722832353229"
293string(16) "6368722832353329"
294string(16) "6368722832353429"
295string(16) "6368722832353529"
296
297*** Testing htmlentities() with NULL as first,second and third argument ***
298string(0) ""
299string(0) ""
300string(0) ""
301
302*** Checking for proper memory allocation with long string ***
303string(198) "&sbquo;&dagger;&trade;&Yuml;&euro;&sbquo;&dagger;&bdquo;&euro;&permil;&hellip;&fnof;&dagger;&bdquo;&euro;&lsquo;&fnof;&lsquo;&dagger;&Dagger;&hellip;&dagger;&circ;&sbquo;&permil;&rsquo;&lsquo;&fnof;"
304
305*** Testing a normal string with htmlentities() ***
306string(42) "&lt;html&gt; This is a test! &lt;/html&gt;"
307
308*** Testing htmlentites() on a quote ***
309string(46) "A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;"
310string(46) "A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;"
311string(36) "A 'quote' is &lt;b&gt;bold&lt;/b&gt;"
312string(36) "A 'quote' is &lt;b&gt;bold&lt;/b&gt;"
313Done
314