What is the best way to encrypt letters in PHP for display?

When encrypting letters in PHP for display, the best way is to use a secure encryption algorithm like AES with a strong key. This will ensure that the data is encrypted securely and can only be decrypted with the correct key. Additionally, it is important to store the key securely and not hardcode it in the code.

// Encryption function
function encryptData($data, $key) {
    $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
    $encrypted = openssl_encrypt($data, 'aes-256-cbc', $key, 0, $iv);
    return base64_encode($iv . $encrypted);
}

// Decryption function
function decryptData($data, $key) {
    $data = base64_decode($data);
    $iv = substr($data, 0, openssl_cipher_iv_length('aes-256-cbc'));
    $encrypted = substr($data, openssl_cipher_iv_length('aes-256-cbc'));
    return openssl_decrypt($encrypted, 'aes-256-cbc', $key, 0, $iv);
}

// Usage
$data = "Hello, World!";
$key = "thisIsAStrongKey123";
$encryptedData = encryptData($data, $key);
echo "Encrypted Data: " . $encryptedData . "\n";
$decryptedData = decryptData($encryptedData, $key);
echo "Decrypted Data: " . $decryptedData;