What is the recommended encryption algorithm to use with openssl_encrypt for short strings in PHP?

When encrypting short strings in PHP using openssl_encrypt, it is recommended to use the AES encryption algorithm with a 256-bit key in CBC mode. This algorithm provides a good balance between security and performance for encrypting short strings.

$data = "Hello, world!";
$key = openssl_random_pseudo_bytes(32); // 256-bit key
$iv = openssl_random_pseudo_bytes(16); // 128-bit IV

$ciphertext = openssl_encrypt($data, 'aes-256-cbc', $key, 0, $iv);

echo "Encrypted data: " . $ciphertext;