What are some common methods for implementing symmetric encryption in PHP, similar to the Caesar cipher?

Symmetric encryption is a method of encryption where the same key is used for both encryption and decryption. In PHP, common methods for implementing symmetric encryption include using the OpenSSL extension, mcrypt extension, or the Sodium extension. These extensions provide functions for encrypting and decrypting data using algorithms such as AES, DES, or Blowfish.

// Using OpenSSL extension for symmetric encryption in PHP
$key = 'secretkey';
$data = 'Hello, World!';

$method = 'aes-256-cbc';
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));

$encrypted = openssl_encrypt($data, $method, $key, 0, $iv);
$decrypted = openssl_decrypt($encrypted, $method, $key, 0, $iv);

echo "Encrypted: $encrypted\n";
echo "Decrypted: $decrypted\n";