What are some common methods for encrypting strings in PHP?

Encrypting strings in PHP is a common practice to secure sensitive information such as passwords, credit card numbers, and personal data. One common method for encrypting strings in PHP is to use the `openssl_encrypt` function with a secure encryption algorithm such as AES-256-CBC. Another method is to use the `mcrypt_encrypt` function, although it is deprecated in newer PHP versions. It's important to securely store the encryption key and initialization vector to ensure the encrypted data can be decrypted later.

// Using openssl_encrypt function
$key = 'your_secret_key';
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
$data = 'sensitive_data_to_encrypt';

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

echo $encrypted;