<?php
$arr = '{
"array_1<script>alert(\"fsdfdf\");</script>":{
"key_1<script>alert(\"fsdfdf\");</script>":"value<script>alert(\"fsdfdf\");</script>",
"key_2":"value",
"key_3":"value",
"key_4":"value",
"array<script>alert(\"fsdfdf\");</script>":{
"key_1<script>alert(\"fsdfdf\");</script>":"value<script>alert(\"fsdfdf\");</script>",
"key_2":"value",
"key_3":"value",
"key_4":"value"
},
"key_5":"value",
"key_6":"value",
"key_7":"value",
"key_8":"value"
},
"array_2":{
"key_1":"value",
"key_2":"value",
"key_3":"value",
"key_4":"value",
"key_5":"value",
"array":{
"key_1":"value",
"key_2":"value",
"key_3":"value",
"key_4":"value"
},
"key_6":"value",
"key_7":"value"
}
}
';
function filterData(Array $in) {
foreach ($in as $key => $value) {
if (is_array($value)) {
filterData($in[$key]);
} else {
$value = trim($value);
$value = strip_tags($value);
$value = htmlspecialchars($value);
$in[$key] = $value;
}
}
return $in;
}
$cleanArray = filterData( json_decode($arr, true) );
echo "<pre>\n";
print_r($cleanArray);
echo "</pre>";
?>
<pre>
Array
(
[array_1<script>alert("fsdfdf");</script>] => Array
(
[key_1<script>alert("fsdfdf");</script>] => value<script>alert("fsdfdf");</script>
[key_2] => value
[key_3] => value
[key_4] => value
[array<script>alert("fsdfdf");</script>] => Array
(
[key_1<script>alert("fsdfdf");</script>] => value<script>alert("fsdfdf");</script>
[key_2] => value
[key_3] => value
[key_4] => value
)
[key_5] => value
[key_6] => value
[key_7] => value
[key_8] => value
)
[array_2] => Array
(
[key_1] => value
[key_2] => value
[key_3] => value
[key_4] => value
[key_5] => value
[array] => Array
(
[key_1] => value
[key_2] => value
[key_3] => value
[key_4] => value
)
[key_6] => value
[key_7] => value
)
)
</pre>
можно ли это реализовать в behaviors()?