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 = "&<\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 = ""&xyz>abc"\n"; 47$s2 = ""&123<456"\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<>"& 63Test 2: &&abc<>"& 64Test 3: a>,\<bc<>"& 65Test 4: a\'\'&bc<>"& 66Test 5: &amp;&lt; 67Test 6: abc<>"& 68Test 7: &&abc<>"& 69Test 8: a>,\<bc<>"& 70Test 9: a\'\'&bc<>"& 71Test 10: &amp;&lt; 72Test 11: abc<>"& 73Test 12: &&abc<>"& 74Test 13: a>,\<bc<>"& 75Test 14: a\'\'&bc<>"& 76Test 15: &amp;&lt; 77Test 16: abc<>"& 78Test 17: &&abc<>"& 79Test 18: a>,\<bc<>"& 80Test 19: a\'\'&bc<>"& 81Test 20: &amp;&lt; 82 83Try with char set option - specify default ISO-8859-1 84Test 21: abc<>"& 85Test 22: &&abc<>"& 86Test 23: a>,\<bc<>"& 87Test 24: &amp;&lt; 88 89Try with double decode FALSE 90Test 25: "&xyz>abc" 91Test 26: "&123<456" 92Test 27: "300 < 400" 93 94Try with double decode TRUE 95Test 28: &quot;&amp;xyz&gt;abc&quot; 96Test 29: &quot;&amp;123&lt;456&quot; 97===DONE=== 98