News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1329158865:v:use_geshi-1:v:type-php

Started by SleePy, Feb 13, 2012, 06:47 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

SleePy

   /**
   * Encodes an email address in multiple ways.
   * @param $str String The email address to encode.
   * @version $url_encode bool Should we use url encoding? Do not use this for displaying, only for mailto: links.
   */
   public function encode_email_address($str, $url_encode = true)
   {
      if (empty($str))
         return;

      $strlength = strlen($str);
      $ret = '';
      for($index = 0; $index < $strlength; $index++)
      {
         $type = rand(1, $url_encode ? 4 : 3);
         $char = $str[$index];
         switch($type)
         {
            case 1: $ret .= '&#' . ord($char) . ';';  break;
            case 2: $ret .= '&#x' . dechex(ord($char)) . ';'; break;
            case 3: $ret .= $char; break;
            case 4: $ret .= '%' . bin2hex($char); break;
         }
      }
      return $ret;
   }
No siggy! :D

SleePy

   /**
   * Encodes an email address in multiple ways.
   * @param $str String The email address to encode.
   * @version $url_encode bool Should we use url encoding? Do not use this for displaying, only for mailto: links.
   */
   public function encode_email_address($str, $url_encode = true)
   {
      if (empty($str))
         return;

      $strlength = strlen($str);
      $ret = '';
      for($index = 0; $index < $strlength; $index++)
      {
         $type = rand(1, $url_encode ? 4 : 3);
         $char = $str[$index];
         switch($type)
         {
            case 1: $ret .= '&#' . ord($char) . ';';  break;
            case 2: $ret .= '&#x' . dechex(ord($char)) . ';'; break;
            case 3: $ret .= $char; break;
            case 4: $ret .= '%' . bin2hex($char); break;
         }
      }
      return $ret;
   }
No siggy! :D