我正在尝试将我的数组中的特殊字符转换为html实体代码:
这是我的帮手数组:
'specialChars' => [
'!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+',
',', '/', ':', ';', '', '?', '@', '[', '\\',
']', '^', '_', '`', '{', '|', '}', '§', '©', '¶'
]
这就是功能:
public static function convert($specialChars = [])
{
$htmlEntityArray = [];
if(count($specialChars) == 0)
{
$specialChars = Config::get('constants.specialChars'); // gets the special char from the helper array
}
foreach ($specialChars as $key => $value)
{
$htmlEntityArray = array_map("htmlentities", $specialChars);
}
return $htmlEntityArray;
}
但是这只会让我返回这个数组,它会成功地转换一些而不是一些:
array:32 [▼
0 => "!"
1 => """
2 => "#"
3 => "$"
4 => "%"
5 => "&"
6 => "'"
7 => "("
8 => ")"
9 => "*"
10 => "+"
11 => ","
12 => "/"
13 => ":"
14 => ";"
15 => "<"
16 => "="
17 => ">"
18 => "?"
19 => "@"
20 => "["
21 => "\"
22 => "]"
23 => "^"
24 => "_"
25 => "`"
26 => "{"
27 => "|"
28 => "}"
29 => "§"
30 => "©"
31 => "¶"
]