String Functions
Advertisements

PHP str_rot13() Function

Topic: PHP String ReferencePrev|Next

Description

The str_rot13() function performs the rot13 transform on a string.

The ROT13 (rotate by 13 places) encoding simply shifts every letter by 13 places in the alphabet. Non-alphabetical characters such as numbers, symbols, whitespace are left unchanged.

The following table summarizes the technical details of this function.

Return Value: Returns the ROT13 version of the given string.
Version: PHP 4.2.0+

Syntax

The basic syntax of the str_rot13() function is given with:

str_rot13(string);

The following example shows the str_rot13() function in action.

<?php
// Sample string
$str = "Apollo 13";

// Perform ROT13 encoding
echo str_rot13($str);
?>

Note: Since there are 26 letters (2×13) in the English alphabet, ROT13 is its own inverse; so the same function can be used for encoding and decoding. Therefore, if you pass an encoded string as argument, the original string will be returned.


Parameters

The str_rot13() function accepts the following parameters.

Parameter Description
string Required. Specifies the string to encode.

More Examples

Here're some more examples showing how str_rot13() function actually works:

The following example demonstrates how to decode ROT13 encoded string using this function.

<?php
// Sample string
$str = "Ncbyyb 13";

// Perform ROT13 decoding
echo str_rot13($str);
?>
Advertisements
Bootstrap UI Design Templates