Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. $result_set = Array
  2. (
  3. [0] => Array
  4. (
  5. [home_id] => 1
  6. [address] => 4225 Nasmyth Dr
  7. [city] => Plano
  8. [state] => TX
  9. [zip] => 76798
  10. )
  11.  
  12. [1] => Array
  13. (
  14. [home_id] => 8
  15. [address] => 4229 Nasmyth Dr
  16. [city] => Plano
  17. [state] => TX
  18. [zip] => 75093
  19. )
  20. );
  21.  
  22. // this doesn't work since $result_set is an array of arrays and htmlspecialchars is expecting a string
  23. htmlspecialchars($result_set, ENT_QUOTES, 'UTF-8'));
  24.  
  25. array_walk_recursive($result_set, "htmlspecialchars", array(ENT_QUOTES,'UTF-8'))
  26.  
  27. function cleanOutput(&$value) {
  28. return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
  29. }
  30. print_r($result_set);
  31. print('-------');
  32. print_r(array_walk_recursive($result_set, "cleanOutput"));
  33.  
  34. Array
  35. (
  36. [0] => Array
  37. (
  38. [home_id] => 1
  39. [address] => 4225 Nasmyth Dr
  40. [city] => Plano
  41. [state] => TX
  42. [zip] => 76798
  43. )
  44. [1] => Array
  45. (
  46. [home_id] => 8
  47. [address] => 4229 Nasmyth Dr
  48. [city] => Plano
  49. [state] => TX
  50. [zip] => 75093
  51. )
  52. )
  53. -------1
  54.  
  55. function cleanOutput(&$value) {
  56. return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
  57. }
  58. $result_set = Array
  59. (
  60. [0] => Array
  61. (
  62. [home_id] => 1
  63. [address] => 4225 Nasmyth Dr
  64. [city] => Plano
  65. [state] => TX
  66. [zip] => 76798
  67. )
  68.  
  69. [1] => Array
  70. (
  71. [home_id] => 8
  72. [address] => 4229 Nasmyth Dr
  73. [city] => Plano
  74. [state] => TX
  75. [zip] => 75093
  76. )
  77. );
  78.  
  79. $cleanedOutput = array();
  80. foreach ($result_set as $rs) {
  81. $cleaned[] = array_map("cleanOutput", $rs);
  82. }
  83. print_r($cleanedOutput);
  84.  
  85. {'homes' : []}
  86.  
  87. function filter(&$value) {
  88. $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
  89. }
  90. array_walk_recursive($result_set, "filter");
  91. print_r($result_set);
  92.  
  93. $cleaned = array_map("htmlspecialchars", $myArray);
  94.  
  95. function myFunc($a) {
  96. return htmlspecialchars($a, ENT_QUOES);
  97. }
  98.  
  99. $cleaned = array_map("myFunc", $myArray);
  100.  
  101. $cleaned = array();
  102. foreach ($result_set as $rs) {
  103. foreach ($rs as $r) {
  104. $cleaned[] = array_map("htmlspecialchars", $r);
  105. }
  106. }
  107.  
  108. array_walk_recursive($myArray, "htmlspecialchars");
  109.  
  110. $clean_array = array_map("htmlspecialchars", $myArray, array(ENT_QUOTES, 'UTF-8'));
  111.  
  112. $clean_array = array_map("htmlspecialchars", $myArray, array(ENT_QUOTES), array('UTF-8'));
  113.  
  114. function secure($val) {
  115. return (is_array($val))?array_map('secure',$val):htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
  116. }
  117.  
  118. function cleanhtml($dirtyhtml) {
  119. return htmlspecialchars($dirtyhtml, UTF-8);
  120. }
  121.  
  122. $cleaned = array_map("cleanhtml", $myArray);
  123.  
  124. function htmlspecialchars_array_modify (&$arr){
  125. array_walk_recursive($arr,function(&$value){
  126. $value=htmlspecialchars($value);
  127. });
  128. return $arr;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement