public static function percentUnEscape($string)
  {
    // Next, repeatedly percent-unescape the URL until it has no more percent-escapes.
    // this is not trivial, because the percent character could be in the url, when are we done?
    // lets unescape till there are no more percentages, or the only percentages are %25 (the % char)
    $keep_unescaping=true;
    while($keep_unescaping){
      if(strpos($string, '%')===false){
        // no % found, done
        break;
      }
      // replace al %25 sequences
      $test_string=preg_replace('#%25#s', '', $string);
      // now see if any % left
      // no? then we must decode exactly one more time
      if(strpos($test_string, '%')===false){
        // no % found
        $keep_unescaping=false;
      }
      $dec_string=urldecode($string);
      if($dec_string==$string){
        // decoding has no effect, bail out
        break;
      }
      $string=$dec_string;
    }
    return $string;
  }