This question already has answers here:
Partially hide email address in PHP
(19 answers)
Closed 5 years ago.
Good Morning Guys! I need to get an e-mail from my database, but I'd like to show it like that:
some*******#hotmail.com
I'd like to show the beginning of my e-mail and then everything after #.
I'm using the following code:
$user_email= "********".substr($linha3['user_email'], -8);
It's working, but sometimes It doesn't appear in a nice way:
********mail.com
May you help me with any solution?
Use RegEx to always match the e-mail username :
echo preg_replace('/.*#/', '***#', 'some_mail#somewhere.net');
$email = $linha3['user_email'];
$email= substr($email, 0, 3).'****'.substr($email, strpos($email, "#"));
Related
This question already has answers here:
get user name from an E-mail address in php
(6 answers)
Closed 2 years ago.
I have an html code which displays user email from php. However i want to trim this part #gmail.com
And display the left part.
Currently I tried this code which is not working.
<p id="p1"><?php
$str = ""
echo $str . "<br>";
echo trim($str,"#gmail.com");
echo htmlspecialchars($_SESSION["username"]);
?></p>
What is the best way to correct it?
For example the email from php database is name1#gmail.com, i want to remove #gmail.com and display only name1
trim() is not the best choice. Simply split email by #:
$expl = explode('#', $str);
echo $expl[0];
This question already has answers here:
Is there a more efficient way to get email suffix than explode? (PHP)
(5 answers)
Closed 3 years ago.
I'm trying to code a PHP script that is given a string with an email address that extracts the username and domain.
For example: username#domain.com -> username | domain.com
I want to take off the "#".
I've tried using trim() but that only works at the start and at the end of a string.
<?php
$email = 'username#domain.com';
$getArray = explode("#",$email);
echo "<pre>";
print_r($getArray);
echo $getArray[0].'<br/>';
echo $getArray[1];
?>
This question already has answers here:
How to validate an email address in PHP
(15 answers)
Closed 5 years ago.
the code is not running can anyone explain why ?
$string1 = "Dean_Johns123#cyber.net.uk"; //Example Email
$pattern = "/^[a-z][_][A-Z][_][0-9]*(#).[a-zA-Z]{2,9}[a-zA-Z]{2,3}.[a-zA-Z]{2}$/";
if(preg_match($pattern , $string1))
{
echo " valid email";
}
else
{
echo "not valid";
}
It would work it you right pattern like this
$pattern = "/^[a-zA-Z0-9_]*(#)[a-zA-Z]{2,9}.[a-zA-Z]{2,3}.[a-zA-Z]{2}$/";
Demo : https://eval.in/850480
The code is not running because the pattern you are using is wrong in syntax you can use
/^([a-z]*)([A-Z]*)([0-9]*)(#)([a-zA-Z]*)([0-9]*).([a-zA-Z]*)([0-9]*).([a-zA-Z]*)([0-9]*)$/ You can visit https://regex101.com/ it explains every part of your regex to you.
This question already has answers here:
How to validate an email address in PHP
(15 answers)
Closed 7 years ago.
I have a php regular expression for email formatting. I used this code below
if ( !(preg_match('/^\w+#[\w.\-]+\.[A-Za-z]{2,3}$/', $email)) ) :
$err_email1 = "<div class = 'error'>Sorry, the email is not formatted properly</div>";
$formerrors = true;
However, it doesn't work when there is a period in the email. i.e. John.Smith#mydomain.com. It works fine with JohnSmith#mydomain.com so I know it's the second period.
How can I modify the code so it works with 2 period? I tried a number of variations but didn't have success.
If you have a good php regular expression site, I am all eyes.
Thanks
Try this
/^([a-z0-9_.-]+)#([\da-z.-]+).([a-z.]{2,6})$/
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP email validation
I'm working on this website, where I have to make a register form. I made it work, but then my friend told me, that some email domain names does have hyphens in them, like;
test#test-tester.com
Right now my code look like this:
preg_match("/^[a-zA-Z0-9._\-]\w+(\.\w+)*\#\w+(\.[a-zA-Z0-9._-]+)*\.[a-zA-Z.]{2,6}$/", $_POST["email"]
What I can see, this should work, but it still does not allow the hyphen.
Anyone know why?
Regex is always useful, but I prefer to use filter_var to validate emails
http://www.php.net/manual/en/filter.filters.validate.php
if(filter_var($email, FILTER_VALIDATE_EMAIL))
{
print('valid Email!');
}
else
{
print('invalid-email =(');
}