PHP str_rot13() Function with Example

By IncludeHelp Last updated : December 27, 2023

PHP str_rot13() Function

The str_rot13() function is a string function, it is used to encode (or decode the encoded string) a string using ROT13 encoding technique.

ROT13 encoding technique is used to encode only alphabets it does not encode the numbers, and other special characters. In ROT13 encoding technique each alphabet shift 13 place in the alphabet table.

Syntax

The syntax of the str_rot13() function:

str_rot13(string);

Parameters

The parameters of the str_rot13() function:

  • string: An input string.

Return Value

The return value of this method is string, it returns the encoded string by ROT13 encoding technique.

Sample Input/Output

Input: "This is IncludeHelp"
Output: "Guvf vf VapyhqrUryc"

Input: "Guvf vf VapyhqrUryc"
Output: "This is IncludeHelp"

Input: "Hello 123 %$#@!"
Output: :Uryyb 123 %$#@!"

Example of PHP str_rot13() Function

<?php
$str = "This is IncludeHelp";
$enc_str = str_rot13($str);
echo ("String = $str \n");
echo ("Encoded string = $enc_str \n");
	
//Here, we will convert encoded string 
//that will be main string
$str = $enc_str;
$enc_str = str_rot13($str);
echo ("String = $str \n");
echo ("Encoded string = $enc_str \n");

//string with numbers & alphabets
$str = "Hello 123 %$#@!";
$enc_str = str_rot13($str);
echo ("String = $str \n");
echo ("Encoded string = $enc_str \n");
?>

Output

The output of the above example is:

String = This is IncludeHelp
Encoded string = Guvf vf VapyhqrUryc
String = Guvf vf VapyhqrUryc
Encoded string = This is IncludeHelp
String = Hello 123 %$#@!
Encoded string = Uryyb 123 %$#@!

To understand the above example, you should have the basic knowledge of the following PHP topics:

All PHP Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.