Home » PHP

PHP str_rot13() Function with Example

PHP str_rot13() Function: Here, we are going to learn about the str_rot13() Function with Example in PHP.
Submitted by IncludeHelp, on February 05, 2019

PHP str_rot13() Function

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:

    str_rot13(string);

It accepts the string and returns the encoded string by ROT13 encoding technique

Examples:

    Input: "This is IncludeHelp"
    Output: "Guvf vf VapyhqrUryc"
    Input: "Guvf vf VapyhqrUryc"
    Output: "This is IncludeHelp"
    Input: "Hello 123 %$#@!"
    Output: :Uryyb 123 %$#@!"

PHP code:

<?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

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 %$#@!




Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.