私は、エンティティコードをHTMLに私の配列内の特殊文字を変換しようとしています:これは私のヘルパー配列であるPHP特殊文字
を:
'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 => "¶"
]
phpの['htmlentities'](http://php.net/manual/en/function.htmlentities.php)や[' htmlspecialchars'](http://php.net/manual /en/function.htmlspecialchars.php)関数は、これを行うように作られています – Jelmergu
私は車輪を再発明していますか? – Akintunde007