In PHP, str_rot13() applies the ROT13 transformation, which shifts each letter 13 places in the alphabet.
Because the alphabet has 26 letters, running it twice gives back the original text. It is a simple way to hide text, not real encryption.
Syntax
Call str_rot13() with the values you need. Start with this line.
PHP
$secret = str_rot13("Hello");
Call
What it does
str_rot13("Hello")
Returns "Uryyb".
str_rot13(str_rot13("Hello"))
Returns "Hello" (it undoes itself).
str_rot13("PHP 8.3!")
Returns "CUC 8.3!" (digits and symbols stay).
Only English letters A to Z and a to z change. Numbers, symbols, and other characters stay as they are. Never use ROT13 to protect passwords or private data.
Library declarations
PHP
str_rot13(string $string): string
Parameters
Parameter
Description
string
Required. The string to transform.
Return Value
Return Value
Description
string
The ROT13 version of the string.
PHP Examples
Example 1 — Shift Letters by 13
Transform a simple word.
PHP
<?php
echo str_rot13("Hello"), PHP_EOL;
Output
Uryyb
How It Works
Pass the word "Hello".
Each letter moves 13 places forward in the alphabet.
H becomes U, e becomes r, l becomes y, and o becomes b.
The new text is "Uryyb".
Example 2 — Undo with a Second Call
Calling the function twice returns the original. Other characters are untouched.