mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2026-06-07 12:38:11 +08:00
fix: 完善 str2arr/arr2str 白名单匹配与空白处理
This commit is contained in:
parent
87a69e2633
commit
8510c65124
@ -201,8 +201,9 @@ if (!function_exists('str2arr')) {
|
|||||||
{
|
{
|
||||||
$items = [];
|
$items = [];
|
||||||
foreach (explode($separ, trim($text, $separ)) as $item) {
|
foreach (explode($separ, trim($text, $separ)) as $item) {
|
||||||
if ($item !== '' && (!is_array($allow) || in_array($item, $allow))) {
|
$item = trim($item);
|
||||||
$items[] = trim($item);
|
if ($item !== '' && (!is_array($allow) || in_array($item, $allow, true))) {
|
||||||
|
$items[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $items;
|
return $items;
|
||||||
@ -218,8 +219,11 @@ if (!function_exists('arr2str')) {
|
|||||||
function arr2str(array $data, string $separ = ',', ?array $allow = null): string
|
function arr2str(array $data, string $separ = ',', ?array $allow = null): string
|
||||||
{
|
{
|
||||||
foreach ($data as $key => $item) {
|
foreach ($data as $key => $item) {
|
||||||
if ($item === '' || (is_array($allow) && !in_array($item, $allow))) {
|
$item = is_string($item) ? trim($item) : $item;
|
||||||
|
if ($item === '' || (is_array($allow) && !in_array($item, $allow, true))) {
|
||||||
unset($data[$key]);
|
unset($data[$key]);
|
||||||
|
} else {
|
||||||
|
$data[$key] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $separ . join($separ, $data) . $separ;
|
return $separ . join($separ, $data) . $separ;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user