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.

Syntax
str_rot13 ($string);
Parameters
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.
Examples
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.
<?php $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.
<?php $string = 'Oevatvat Xabjyrqtr Gbtrgure'; $decoded = str_rot13($string); echo $decoded; ?>
OUTPUT: Bringing Knowledge Together
Conclusion
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.

Vishesh is currently working as an Intermediate Software Engineer with Orion Health, New Zealand. He graduated with a Masters in Information Technology from the University of Auckland in 2021. With more than 4 years of work experience, his expertise includes Java, Python, Machine Learning, PHP, Databases, Design and Architecture.