@ 2014-07-13T11:45:05Z <?php
define("TYPE_HTML_TEXT",1);
define("TYPE_NUMBER", 2);
define("TYPE_BOOLEAN", 3);
define("TYPE_SCRIPT", 4);
define("TYPE_BINARY", 5);
define("TYPE_URL", 6);
define("TYPE_LIST_ITEM", 7);
define("TYPE_LIST", 8);
define("TYPE_COLOR", 9);
define("TYPE_CSS_ATTR", 10);
define("TYPE_CSS_ATTR_COLOR", 11);
define("TYPE_CSS_ATTR_SIZE", 12);
define("TYPE_CSS_CUSTOM", 13);
define("TYPE_SIZE", 14);
define("TYPE_CDATA", 15);
define("TYPE_CONFIG", 16);
define("TYPE_HTML_MARKUP", 17);
/**
* ord() alternative that works with UTF8 characters
* @param string $c
*
* @return int UTF-8 character code value
*/
function getUTF8CharCode($c) {
$h = ord($c{0});
if ($h <= 0x7F) {
return $h;
} else if ($h < 0xC2) {
return false;
} else if ($h <= 0xDF) {
return ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F);
} else if ($h <= 0xEF) {
return ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6
| (ord($c{2}) & 0x3F);
} else if ($h <= 0xF4) {
return ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12
| (ord($c{2}) & 0x3F) << 6
| (ord($c{3}) & 0x3F);
} else {
return -1;
}
}
/**
* Escape a single character for CSS context.
* @param $c
* @return string
*/
function escapeCSSCharacter($c) {
return "\\" . base_convert(getUTF8CharCode($c), 10, 16) . " ";
}
/**
* Escape CSS rule
*
* @param string $data The CSS rule
* @param array $immuneChars Array of immune character. These characters will not be escaped.
*
* @return string Escaped string
*/
function escapeCSSValue($data, array $immuneChars = array()) {
$result = "";
for ($i = 0; $i < mb_strlen($data); $i++) {
$currChar = mb_substr($data, $i, 1);
if (getUTF8CharCode($currChar) < 256 && //Character with ASCII value of 255 or less are dangerous!
!preg_match("/^\w$/", $currChar) && //Alphanumeric and underscores are safe.
!in_array($currChar, $immuneChars) //Immune characters are safe.
) {
$result .= escapeCSSCharacter($currChar);
}
else {
$result .= $currChar;
}
}
return $result;
}
function encodeJSONProperty($type, $value, $raw = false) {
global $ESCAPE_PROPERTIES;
if ($raw || !$ESCAPE_PROPERTIES) { //$raw == true means to explicitly not escape.
//$ESCAPE_PROPERTIES is the feature flag. True means we want escaping.
return $value;
}
switch ($type) {
case TYPE_HTML_TEXT:
return htmlspecialchars($value);
case TYPE_CONFIG:
case TYPE_LIST_ITEM:
case TYPE_LIST:
case TYPE_HTML_MARKUP:
return $value;
case TYPE_NUMBER:
return (int)$value;
case TYPE_BOOLEAN:
return stristr($value, "true") != false;
case TYPE_SCRIPT:
return new JSONFunction($value);
case TYPE_URL:
return urlencode($value);
case TYPE_COLOR:
case TYPE_SIZE:
return escapeCSSValue($value, array("#", ",", ".", "(", ")", "-", "%", "*", "+", "=", "/"));
}
}
echo encodeJSONProperty(TYPE_HTML_TEXT, <script>Evil</script>);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.30 0.011 0.047 12.55 5.4.29 0.009 0.052 12.54 5.4.28 0.006 0.051 12.43 5.4.27 0.009 0.047 12.43 5.4.26 0.009 0.050 12.44 5.4.25 0.009 0.050 12.44 5.4.24 0.008 0.043 12.44 5.4.23 0.010 0.046 12.43 5.4.22 0.010 0.048 12.43 5.4.21 0.008 0.049 12.43 5.4.20 0.009 0.050 12.43 5.4.19 0.012 0.046 12.42 5.4.18 0.008 0.050 12.43 5.4.17 0.006 0.052 12.43 5.4.16 0.009 0.045 12.43 5.4.15 0.006 0.048 12.42 5.4.14 0.005 0.054 12.11 5.4.13 0.009 0.056 12.09 5.4.12 0.011 0.083 12.06 5.4.11 0.014 0.056 12.05 5.4.10 0.012 0.046 12.06 5.4.9 0.010 0.057 12.05 5.4.8 0.009 0.053 12.05 5.4.7 0.005 0.054 12.05 5.4.6 0.008 0.050 12.05 5.4.5 0.010 0.047 12.05 5.4.4 0.012 0.045 12.04 5.4.3 0.008 0.055 12.04 5.4.2 0.023 0.064 12.03 5.4.1 0.013 0.060 12.04 5.4.0 0.014 0.059 11.53 5.3.28 0.010 0.058 12.71 5.3.27 0.015 0.058 12.73 5.3.26 0.010 0.059 12.73 5.3.25 0.014 0.050 12.73 5.3.24 0.012 0.054 12.73 5.3.23 0.013 0.059 12.72 5.3.22 0.011 0.056 12.69 5.3.21 0.006 0.048 12.69 5.3.20 0.007 0.048 12.69 5.3.19 0.009 0.053 12.69 5.3.18 0.014 0.039 12.68 5.3.17 0.007 0.051 12.68 5.3.16 0.008 0.051 12.68 5.3.15 0.009 0.050 12.68 5.3.14 0.010 0.049 12.68 5.3.13 0.011 0.049 12.67 5.3.12 0.014 0.062 12.67 5.3.11 0.015 0.070 12.67 5.3.10 0.015 0.055 12.16 5.3.9 0.007 0.048 12.14 5.3.8 0.010 0.048 12.13 5.3.7 0.013 0.045 12.13 5.3.6 0.012 0.046 12.11 5.3.5 0.008 0.047 12.06 5.3.4 0.015 0.071 12.06 5.3.3 0.014 0.062 12.03 5.3.2 0.014 0.049 11.80 5.3.1 0.008 0.055 11.77 5.3.0 0.016 0.109 11.75
preferences:dark mode live preview
138.94 ms | 1394 KiB | 7 Q