<?php

/*
 * URL Encoder script.
 * Version 1.0 - February 2002
 * Version 1.1 - December 2007 - added transpose2 - a delayed action on decoding
 * (c) 2002, Paul Gregg <pgregg@pgregg.com>
 * http://www.pgregg.com
 *
 * Function: Take an href link and the visible text and make an obfuscated
 * link to prevent search engines (or spam harvesters) from picking it up.
 *
 * Open Source Code:   If you use this code on your site for public
 * access (i.e. on the Internet) then you must attribute the author and
 * source web site: http://www.pgregg.com/projects/
 * You must also make this original source code available for download
 * unmodified or provide a link to the source.  Additionally you must provide
 * the source to any modified or translated versions or derivatives.
 *
 * PHP function-ised version.
 */


  
Function transpose($str) {
    
# function takes the string and swaps the order of each group of 2 chars
    
$len strlen($str);
    
$ret "";
    for (
$i=0$i<$len$i=$i+2) {
      if (
$i+== $len)
        
$ret .= substr($str$i1);
      else
        
$ret .= sprintf("%s%s"substr($str$i+11), substr($str$i1));
    }
    return 
$ret;
  }
  
  Function 
escapeencode ($str) {
    
$ret "";
    
$arr unpack("C*"$str);
    foreach (
$arr as $char)
      
$ret .= sprintf("%%%X"$char);
    return 
$ret;
  }
  
  Function 
encodelink($href$text) {
    
$code sprintf("var s='%s';var r='';for(var i=0;i<s.length;i++,i++){r=r+s.substring(i+1,i+2)+s.substring(i,i+1)}document.write('<a href=\"'+r+'\">%s</a>');"transpose($href), $text);
    
$UserCode sprintf("%s%s%s",
    
"<SCRIPT type=\"text/javascript\">eval(unescape('",
    
escapeencode($code),
    
"'))</SCRIPT>");
    return 
$UserCode;
  }

  Function 
encodelink_delayed($href$text) {
    
$code sprintf("function pgregg_transpose2(h) {var s='%s';var r='';for(var i=0;i<s.length;i++,i++){r=r+s.substring(i+1,i+2)+s.substring(i,i+1)}h.href=r;}document.write('<a href=\"#\" onMouseOver=\"javascript:pgregg_transpose2(this)\" onFocus=\"javascript:pgregg_transpose2(this)\">%s</a>');"transpose($href), $text);
    
$UserCode sprintf("%s%s%s",
        
"<SCRIPT type=\"text/javascript\">eval(unescape('",
        
escapeencode($code),
        
"'))</SCRIPT>");
    return 
$UserCode;
  }
?>