add clear

This commit is contained in:
2020-04-30 22:09:08 +08:00
parent 7bda1dbcce
commit 44146ad916
6 changed files with 236 additions and 257 deletions
+24
View File
@@ -81,6 +81,30 @@ class Help extends Miniprogarampage
return $xml;
}
/**
* @param mixed $json
* @return false|mixed|string
*/
public static function toJson($json)
{
if (is_object($json)) {
$json = get_object_vars($json);
}
if (is_array($json)) {
return json_encode($json, JSON_UNESCAPED_UNICODE);
}
$matchQuote = '/(<\?xml.*?\?>)?<([a-zA-Z_]+)>(<([a-zA-Z_]+)><!.*?><\/\4>)+<\/\2>/';
if (preg_match($matchQuote, $json)) {
$json = self::xmlToArray($json);
} else {
$json = json_decode($json, true);
}
if (!is_array($json)) {
$json = [];
}
return json_encode($json, JSON_UNESCAPED_UNICODE);
}
/**
* @param int $length
* @return string