PHP Provides str_rot13 function to rotate alphabetic characters by 13 places. However, there is no str_rot47 function to rotate 47 places over a larger mapping table. The following is a quick rot47 function add-on you can easily use in your PHP application. The quick implementation is possible by using PHP strstr function that practically-fast maps a set of characters to another set.
This previous post talks about rotating functions implementation in batch.
if (!function_exists('str_rot47')) {
function str_rot47($str) {
return strtr($str,
'!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~',
'PQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO'
);
}
}
You could refer to this site for more rot47 implementations. You could also write a function to invoke the API like this:
function remote_str_rot47($str) {
$data = file_get_contents("https://helloacm.com/api/rot47/?s=$str");
return json_decode($data, true);
}
ROT47 Online Encoder & Decoder
- Online (Client-side) Javascript ROT47 Encoder & Decoder
- Online (Server-side) PHP ROT47 Encoder & Decoder
–EOF (The Ultimate Computing & Technology Blog) —
Last Post: Longest Increasing Sequence
Next Post: WordPress URL Rewrite Rules Explained