From be4d218af17a12a9e21bcd6c01086ea3bf2541b5 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Thu, 26 Sep 2013 17:33:44 +0000 Subject: [PATCH] Add sanitation function. --- includes/utilities.inc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/includes/utilities.inc b/includes/utilities.inc index 6366305e..2139ae09 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -908,3 +908,19 @@ function islandora_as_renderable_array(&$markup_array) { } unset($value); } + +/** + * Sanitizes an input string to be valid XML. + * + * @param string $input + * An input string. + * @param string $replacement + * What we are replacing invalid characters with, defaults to ''. + * + * @return string + * The sanitized string. + */ +function islandora_sanitize_input_for_valid_xml($input, $replacement = '') { + $input = preg_replace('/[^\x9\xA\xD\x20-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u', $replacement, $input); + return $input; +}