Skip to content

Instantly share code, notes, and snippets.

@mrclay
Created September 19, 2011 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrclay/1225832 to your computer and use it in GitHub Desktop.
Save mrclay/1225832 to your computer and use it in GitHub Desktop.
RotUrl: encode/obfuscate URLs for use in other URLs
<?php
/**
* Rot35 for URLs. To avoid increasing size during urlencode(), commonly encoded
* chars are mapped to more rarely used chars (end of the uppercase alpha).
*
* @param string $url
* @return string
*/
function rotUrl($url) {
return strtr($url,
'./-:?=&%# ZQXJKVWPY abcdefghijklmnopqrstuvwxyz123456789ABCDEFGHILMNORSTU',
'ZQXJKVWPY ./-:?=&%# 123456789ABCDEFGHILMNORSTUabcdefghijklmnopqrstuvwxyz');
}
@gaabora
Copy link

gaabora commented Oct 18, 2019

We must save this conversation here as a future usage note tho.
So for safe usage

urlencode(rotUrl($url)) // to encode 
rotUrl(urldecode($url)) // to decode 

http://codepad.org/rz0faInK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment