Home > Backend Development > PHP Tutorial > 如何把一个文本中的Email用*隐藏

如何把一个文本中的Email用*隐藏

WBOY
Release: 2016-06-06 20:13:50
Original
1130 people have browsed it

如何隐藏下面一段文本中的email地址?
$str = '汉字的是scdd test001@qq.com asda test002@qq.com 你后am test009@aa.com 最后一个邮箱 defse@ff.com';
预期的结果是:

<code>汉字的是scdd *******@qq.com asda *******@qq.com 你后am *******@aa.com 最后一个邮箱 *****@ff.com</code>
Copy after login
Copy after login

回复内容:

如何隐藏下面一段文本中的email地址?
$str = '汉字的是scdd test001@qq.com asda test002@qq.com 你后am test009@aa.com 最后一个邮箱 defse@ff.com';
预期的结果是:

<code>汉字的是scdd *******@qq.com asda *******@qq.com 你后am *******@aa.com 最后一个邮箱 *****@ff.com</code>
Copy after login
Copy after login

<code>
$str = '汉字的是scdd test001@qq.com asda test002@qq.com 你后am test009@aa.com 最后一个邮箱 defse@ff.com';
$replace = "*";
echo preg_replace_callback('/([a-zA-Z0-9]*)@([a-zA-Z0-9]*\.com)/',
    function($matches) use ($replace){
        return str_repeat($replace,strlen($matches[1]))."@".$matches[2];
},
    $str);</code>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template