Partially hide email address in PHP

Bluemagica

I am building a simple friend/buddy system, and when someone tries to search for new friends, I want to show partially hidden email addresses, so as to give an idea about who the user might be, without revealing the actual details.

So I want [email protected] to become abcdl******@hotmail.com.

As a test I wrote:

<?php
$email = "[email protected]";

$em = explode("@",$email);
$name = $em[0];
$len = strlen($name);
$showLen = floor($len/2);
$str_arr = str_split($name);
for($ii=$showLen;$ii<$len;$ii++){
    $str_arr[$ii] = '*';
}
$em[0] = implode('',$str_arr); 
$new_name = implode('@',$em);
echo $new_name;

This works, but I was wondering if there was any easier/shorter way of applying the same logic? Like a regex maybe?

msturdy

here's something quick:

function obfuscate_email($email)
{
    $em   = explode("@",$email);
    $name = implode('@', array_slice($em, 0, count($em)-1));
    $len  = floor(strlen($name)/2);

    return substr($name,0, $len) . str_repeat('*', $len) . "@" . end($em);   
}

// to see in action:
$emails = ['"Abc\@def"@iana.org', '[email protected]'];

foreach ($emails as $email) 
{
    echo obfuscate_email($email) . "\n";
}

echoes:

"Abc\*****@iana.org
abcdl*****@hotmail.com

uses substr() and str_repeat()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Partially hide email address in TypeScript(Javascript)

From Dev

Partially hide email address with RegEx and Javascript

From Dev

Partially hiding an email address with PHP regex

From Dev

Hide part of email address in php

From Java

Partially mask email address - javascript

From Dev

How can hide the email address

From Dev

Hide "To Email" Address when sending email

From Dev

Hide characters in email address...(asterisk it)

From Dev

How to hide the email address of users in Alfresco?

From Dev

Hide characters in email address using an SQL query

From Dev

PHP mail is not sending email to my email address

From Dev

PHP mail is not sending email to my email address

From Dev

Is a valid paypal email address or not (PHP)

From Dev

Parse email sent to an address with PHP?

From Dev

Hide author email address from Google Sheets API

From Dev

Hide shipping address on local pickup in WooCommerce email notifications

From Dev

using regular expression to hide email address from spam bots

From Dev

Extract email address from string - php

From Dev

PHP Send email to multiple address from SQL

From Dev

PHP, Validate if user entered an email domain, NOT address

From Dev

php live search email address after @

From Dev

PHP Arrays - Sort by Email Address Domain (alternate)

From Dev

sending an email in php to an address stored in database

From Dev

Parse name from full email address in PHP

From Dev

Checking if email address exists in SQL database with php

From Dev

Hide a partially shown div

From Dev

php mail function from email address shows mail server address

From Dev

My PHP form submits but does not validate the email address

From Dev

how to add email address to mailchimp list using api call in php

Related Related

  1. 1

    Partially hide email address in TypeScript(Javascript)

  2. 2

    Partially hide email address with RegEx and Javascript

  3. 3

    Partially hiding an email address with PHP regex

  4. 4

    Hide part of email address in php

  5. 5

    Partially mask email address - javascript

  6. 6

    How can hide the email address

  7. 7

    Hide "To Email" Address when sending email

  8. 8

    Hide characters in email address...(asterisk it)

  9. 9

    How to hide the email address of users in Alfresco?

  10. 10

    Hide characters in email address using an SQL query

  11. 11

    PHP mail is not sending email to my email address

  12. 12

    PHP mail is not sending email to my email address

  13. 13

    Is a valid paypal email address or not (PHP)

  14. 14

    Parse email sent to an address with PHP?

  15. 15

    Hide author email address from Google Sheets API

  16. 16

    Hide shipping address on local pickup in WooCommerce email notifications

  17. 17

    using regular expression to hide email address from spam bots

  18. 18

    Extract email address from string - php

  19. 19

    PHP Send email to multiple address from SQL

  20. 20

    PHP, Validate if user entered an email domain, NOT address

  21. 21

    php live search email address after @

  22. 22

    PHP Arrays - Sort by Email Address Domain (alternate)

  23. 23

    sending an email in php to an address stored in database

  24. 24

    Parse name from full email address in PHP

  25. 25

    Checking if email address exists in SQL database with php

  26. 26

    Hide a partially shown div

  27. 27

    php mail function from email address shows mail server address

  28. 28

    My PHP form submits but does not validate the email address

  29. 29

    how to add email address to mailchimp list using api call in php

HotTag

Archive