0

I'm making something for me and my friends So, i have a array with symbols. It looks like

$array = [
   "0" => "000a "
]

I put there "♧" => "100a " but it is not finding the and any other special characters in the array. Whats the reason for that and how to fix it?

<?php 
    $default = [
        "0" => "000a ",
        "1" => "000b ",
        "2" => "000c ",
        "3" => "000d ",
        "4" => "000e ",
        "5" => "000f ",
        "6" => "000g ",
        "7" => "000h ",
        "8" => "000i ",
        "9" => "000j ",
        "a" => "001a ",
        "A" => "002a ",
        "b" => "003a ",
        "B" => "004a ",
        "c" => "005a ",
        "C" => "006a ",
        "d" => "007a ",
        "D" => "008a ",
        "e" => "009a ",
        "E" => "010a ",
        "f" => "011a ",
        "F" => "012a ",
        "g" => "013a ",
        "G" => "014a ",
        "h" => "015a ",
        "H" => "016a ",
        "i" => "017a ",
        "I" => "018a ",
        "j" => "019a ",
        "J" => "020a ",
        "k" => "021a ",
        "K" => "022a ",
        "l" => "023a ",
        "L" => "024a ",
        "m" => "025a ",
        "M" => "026a ",
        "n" => "027a ",
        "N" => "028a ",
        "o" => "029a ",
        "O" => "030a ",
        "p" => "031a ",
        "P" => "032a ",
        "q" => "033a ",
        "Q" => "034a ",
        "r" => "035a ",
        "R" => "036a ",
        "s" => "037a ",
        "S" => "038a ",
        "t" => "039a ",
        "T" => "040a ",
        "u" => "041a ",
        "U" => "042a ",
        "v" => "043a ",
        "V" => "044a ",
        "w" => "045a ",
        "W" => "046a ",
        "x" => "047a ",
        "X" => "048a ",
        "y" => "049a ",
        "Y" => "050a ",
        "z" => "051a ",
        "Z" => "052a ",
        "!" => "053a ",
        "?" => "054a ",
        "," => "055a ",
        "." => "056a ",
        "_" => "057a ",
        "(" => "058a ",
        ")" => "059a ",
        "$" => "060a ",
        " " => "061a ",
        "/" => "062a ",
        "=" => "063a ",
        "#" => "064a ",
        "@" => "065a ",
        "%" => "066a ",
        "^" => "067a ",
        "&" => "068a ",
        "*" => "069a ",
        "-" => "070a ",
        "'" => "071a ",
        '"' => "072a ",
        ":" => "073a ",
        ";" => "074a ",
        "+" => "075a ",
        "×" => "076a ",
        "÷" => "077a ",
        "€" => "078a ",
        "£" => "079a ",
        "¥" => "080a ",
        "₩" => "081a ",
        "`" => "082a ",
        "~" => "083a ",
        "\\" => "084a ",
        "|" => "085a ",
        "<" => "086a ",
        ">" => "087a ",
        "{" => "088a ",
        "}" => "089a ",
        "[" => "090a ",
        "]" => "091a ",
        "▪︎" => "092a ",
        "○" => "093a ",
        "●" => "094a ",
        "□" => "095a ",
        "■" => "096a ",
        "♤" => "097a ",
        "♡" => "098a ",
        "◇" => "099a ",
        "♧" => "100a ",
        "☆" => "101a ",
        "⊙" => "102a ",
        "°" => "103a ",
        "•" => "104a ",
        "¤" => "105a ",
        "《" => "106a ",
        "》" => "107a ",
        "¡" => "108a ",
        "¿" => "109a ",
        "₽" => "110a ",
        "а" => "111a "
    ];

    $converted = '';
    $convertionType = $_GET["type"];
    foreach ( str_split($_GET['inputText']) as $val) {
        $converted = $converted . $default[$val];
    }
    echo $converted
    ?>

1 Answers1

0

What you should do is convert your keys to utf8 so for example instead of "♡" you use "\xe2\x99\xa1"

Displaying a utf8 char is easy with json_decode so :

<?php
$chr = "\xe2\x99\xa1";
$chr2 = "\xe2\x99\xa4";
echo json_decode('"'.$chr.'"');
$array[$chr] = "Something";
$array[$chr2] = "SomeValue";
echo '<pre>';
print_r($array);
echo '<pre>';
print_r($array[$chr]);
echo '<pre>';
print_r($array[$chr2]);

This will return this:

♡
Array
(
    [♡] => Something
    [♤] => SomeValue
)
Something
SomeValue

You should know all of the utf8 of your keys before hand. ... https://www.browserling.com/tools/utf8-encode < good online tool.

Shlomtzion
  • 674
  • 5
  • 12