<?php
function stringToArray($string)
{
preg_match_all('/
\s*(\w+) # key \\1
\s*=\s* # =
(\'|")? # values may be included in \' or " \\2
(.*?) # value \\3
(?(2) \\2) # matching \' or " if needed \\4
\s*(?:
(?=\w+\s*=) | \s*$ # followed by another key= or the end of the string
)
/x', $string, $matches, PREG_SET_ORDER);
$attributes = array();
foreach ($matches as $val)
{
$attributes[$val[1]] = literalize($val[3]);
}
return $attributes;
}
function literalize($value, $quoted = false)
{
// lowercase our value for comparison
$value = trim($value);
$lvalue = strtolower($value);
if (in_array($lvalue, array('null', '~', '')))
{
$value = null;
}
else if (in_array($lvalue, array('true', 'on', '+', 'yes')))
{
$value = true;
}
else if (in_array($lvalue, array('false', 'off', '-', 'no')))
{
$value = false;
}
else if (ctype_digit($value))
{
$value = (int) $value;
}
else if (is_numeric($value))
{
$value = (float) $value;
}
else
{
//$value = self::replaceConstants($value);
if ($quoted)
{
$value = '\''.str_replace('\'', '\\\'', $value).'\'';
}
}
return $value;
}
echo json_encode(stringToArray("onclick=\"double_list_move(\$('hi'), \$('hi')); return false;\""));
?>
- Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- {"onclick":"double_list_move($('hi'), $('hi')); return false;"}
preferences:
201.47 ms | 404 KiB | 331 Q