简体   繁体   English

PHP将两个preg_replace合并为一个,用于隐藏电子邮件和电话

[英]PHP combine two preg_replace into one for email and phone hiding

I got the email and phone to be hidden individually. 我将电子邮件和电话分别隐藏了。 How can I get the two combined so that I can run a check on one string and if email and/or phone are found the replace them. 如何将两者结合在一起,以便可以对一个字符串进行检查,如果找到电子邮件和/或电话,请替换它们。

$string= 'text text example@domain.com blalba blalba blalba 777 777 7777 blalba blalba';

$hide_email = preg_replace('/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})/', '[hide email]', $string);
$hide_phone = preg_replace('/[(]*\d{3}[)]*\s*[.\-\s]*\d{3}[.\-\s]*\d{4}/', '[hide phone]', $string);

echo $string; //hide the email and/or phone found

Copy and pasted your code above. 复制并粘贴上面的代码。

$string= 'text text example@domain.com blalba blalba blalba 777 777 7777 blalba blalba';

$string = preg_replace('/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,6})/', '[hide email]', $string); $ string = preg_replace('/([[a-zA-Z0-9 ._%+-] + @ [a-zA-Z0-9 .-] +。[a-zA-Z] {2,6}) /','[隐藏电子邮件]',$ string); $string = preg_replace('/[(] \\d{3}[)] \\s*[.-\\s] \\d{3}[.-\\s] \\d{4}/', '[hide phone]', $string); $ string = preg_replace('/ [(] \\ d {3} [)] \\ s * [.- \\ s] \\ d {3} [.- \\ s] \\ d {4} /','[隐藏电话]',$ string);

echo $string; echo $ string; //hide the email and/or phone found //隐藏找到的电子邮件和/或电话

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM