PHP编码电子邮件地址

PHP编码电子邮件地址

本文介绍了PHP编码电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 PHP 中使用 a-zA-Z0-9 编码电子邮件地址>所以基本上编码没有任何特殊字符,但然后能够解码回到原来的。



示例:

  [email protected] => ENCODE => n6bvJjdh7w6QbdVB373483ydbKus7Qx 
n6bvJjdh7w6QbdVB373483ydbKus7Qx => DECODE => [email protected]

这甚至可能吗?

  / / encode 
$ email_encoded = rtrim(strtr(base64_encode($ email),'+ /','-_'),'=');

//解码
$ email_decoded = base64_decode(strtr($ email_encoded,'-_','+ /'));

它将 + - _ 中的base64字母表中的$ c> / 。编码步骤还会在需要时删除尾部 = 字符。


I need a way in PHP to encode an e-mail address only using a-zA-Z0-9 so basically encoded without any special characters, but then be able to decode it back to the original.

Example:

 [email protected] => ENCODE => n6bvJjdh7w6QbdVB373483ydbKus7Qx
 n6bvJjdh7w6QbdVB373483ydbKus7Qx => DECODE => [email protected]

Is this even possible?

解决方案

You can do a web safe base64 encode:

// encode
$email_encoded = rtrim(strtr(base64_encode($email), '+/', '-_'), '=');

// decode
$email_decoded = base64_decode(strtr($email_encoded, '-_', '+/'));

It converts the + and / from the base64 alphabet in the more harmless - and _. The encoding step also removes the trailing = characters when needed.

这篇关于PHP编码电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 12:59