Formated Paste

  1. /**
  2. * Encodes an email address in multiple ways.
  3. * @param $str String The email address to encode.
  4. * @version $url_encode bool Should we use url encoding? Do not use this for displaying, only for mailto: links.
  5. */
  6. public function encode_email_address($str, $url_encode = true)
  7. {
  8. if (empty($str))
  9. return;
  10.  
  11. $strlength = strlen($str);
  12. $ret = '';
  13. for($index = 0; $index < $strlength; $index++)
  14. {
  15. $type = rand(1, $url_encode ? 4 : 3);
  16. $char = $str[$index];
  17. switch($type)
  18. {
  19. case 1: $ret .= '&#' . ord($char) . ';'; break;
  20. case 2: $ret .= '&#x' . dechex(ord($char)) . ';'; break;
  21. case 3: $ret .= $char; break;
  22. case 4: $ret .= '%' . bin2hex($char); break;
  23. }
  24. }
  25. return $ret;
  26. }
  27.  
Name:
Email:
Code/text to paste:
  • Enable code highlighting
  • Code Language:
  • What software do we use to power the pastebin?: