PHP str_rot13 Function | rot13 Transform on a String

PHP str_rot13 is an inbuilt string function in PHP. It performs ROT13 transformation on a string by excluding numeric and non-alphanumeric characters. Also, if you input an encoded string, the function returns the original string back. In this article, we will discuss the PHP str_rot13 Function. Also, we will discuss a few examples of using it.

Note: The ROT13 transformation shifts every letter by 13 places in the alphabet. However, it does not change any numeric or non-alphanumeric character. Also, the same function performs encoding and decoding. Therefore, on passing the already encoded string will return the original string.

ROT13 Function in PHP
ROT13 Transformation. Source: Wikipedia


str_rot13 ($string);


The PHP str_rot13 function expects only one parameter. The string which you want to encode/decode is the input to the function.

Return Value

The str_rot13 function in PHP returns the string after applying ROT13 transformation.


Let’s discuss a few examples of using the function.

Example 1: Encoding a String

For instance, consider an example of ROT13 encoding a string using the function.


	$string = 'Bringing Knowledge Together';
	$encoded = str_rot13($string);
	echo $encoded;


The final string after rotating all the alphabets by 13 characters is:

Oevatvat Xabjyrqtr Gbtrgure

Example 2: Decoding a String

Similarly, we can pass the encoded string to the function to obtain the original string again.


	$string = 'Oevatvat Xabjyrqtr Gbtrgure';
	$decoded = str_rot13($string);
	echo $decoded;

Bringing Knowledge Together


In conclusion, we discussed the PHP str_rot13 function. You can read more about it on the Official PHP Documentation. Additionally, you can also learn more PHP String Functions on Concatly.

Spread the Knowledge

Leave a Reply

Your email address will not be published. Required fields are marked *