- Rencoding UTF-8 to manage problematics strings in data to encode
This commit is contained in:
parent
4c3772376c
commit
5bac6cd843
|
@ -23,16 +23,32 @@ class JsonExtension implements Extension, FunctionExtension {
|
||||||
return "<?php echo htmlentities(json_encode($arguments, {$this->flags}), ENT_QUOTES, 'UTF-8') ?>";
|
return "<?php echo htmlentities(json_encode($arguments, {$this->flags}), ENT_QUOTES, 'UTF-8') ?>";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "<?php echo json_encode($arguments, $flag) ?>";
|
$cls = static::class;
|
||||||
|
|
||||||
|
return "<?php echo json_encode(\\$cls::utf8($arguments), $flag) ?>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function exportFunctions(): array
|
public function exportFunctions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'json' => function($arguments, ? int $flags = null) {
|
'json' => function($arguments, ? int $flags = null) {
|
||||||
return json_encode($arguments, \JSON_FORCE_OBJECT);
|
return json_encode($arguments, \JSON_FORCE_OBJECT);
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function utf8($src) {
|
||||||
|
|
||||||
|
if (is_array($src)) {
|
||||||
|
foreach ($src as $key => $value) {
|
||||||
|
$src[$key] = static::utf8($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif (is_string($src)) {
|
||||||
|
return mb_convert_encoding($src, "UTF-8", "UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $src;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue