The `str_rot13()` function in PHP performs the ROT13 transform on a string. ROT13 is a simple letter substitution cipher that replaces a letter with the 13th letter after it in the alphabet.PHP 8,PHP 8.1,PHP 8.2,PHP 8.3 and PHP 8.4.
Basic Usage<?php$string = "Hello World";$encoded = str_rot13($string);echo $encoded; // Outputs: Uryyb Jbeyq$decoded = str_rot13($encoded);echo $decoded; // Outputs: Hello World
Characteristics of ROT13 in PHP1. Reversible**: Applying ROT13 twice returns the original string2. Case-preserving**: Maintains the original letter case3. Non-alphabet characters**: Leaves numbers, symbols, and non-alphabet characters unchanged
Example with Different Character Types<?php$text = "PHP 8.2 is awesome! 123";$rot13 = str_rot13($text);echo $rot13; // Outputs: CUC 8.2 vf njrfbzr! 123?>
Limitations1.Not secure for real encryption (trivial to decode)2. Only works with basic Latin alphabet (A-Z, a-z)3. Doesn't handle Unicode/multibyte charactersFor real security needs, use PHP's `openssl` or `sodium` extensions instead.