SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

Getting the domain and userid part from an email address

We can separate domain part and userid part of an email address in many ways. One of the easiest ways is to use split command to break the email address in two parts. As we know every email address will have one @ within it so we will break the string storing the email address using this @. The output of split command will give us an array with two elements. The first part is the userid and second part is domain part. Here is the code to get domain and userid part from a email address.





$em="mynam@domain.com";
$ar=split("@",$em);
echo $ar[0];
echo "<br>";
echo $ar[1];


If we have more than one email address in a string then we have to break the string first to get all the email address first. For example if we have one CSV file storing all the email address then first we have to break the file to get individual email address and then again use the split command to get the domain and userid part from the address. Here is the code.

$em="mynam@domain.com,second@second.com,
third@third.com,fourth@fourth.com";

$ar=split(",",$em);

while (list ($key, $val) = each ($ar)) {
$ar2=split("@",$val);
echo $ar2[0];
echo "<br>";
echo $ar2[1];
echo "<br><br>";
}

Read how breaking of email address is done using JavaScript

Discuss this tutorial at forum


PHP String Functions
All String Functions in PHP
str_replace: How to replace a part of a string with another string
str_ireplace: Case in-sensitive search and replace using array of strings
strlen: How to find length of a string in PHP?
trim: Removing empty space from both sides of a string
strrev: Reversing a string by using strrev function in PHP
Adding two or more strings in PHP
stristr: Searching for a presence of a string inside another string
nl2br: Adding Line breaks inside a string in place of carriage returns
split: Breaking a string to form array using delimiters
substr: Collecting part of a string
substr_count: Counting occurrence of sub string in main string
str_repeat: Repeating a string number of times
strtolower(): function to change alphabets to Lower case
strtoupper(): function to change characters to upper case letters
function to collect part of a string with two landmarks
Random string generator with number and alphabets for password
strcasecmp(): Case insensitive string comparison
strcmp(): Case sensitive string comparison
str_pad(): String pad with specified length
md5 hash of a string: encryption of a string
Separating domain and userid part from an email address using split
htmlspecialchars: Printing html special chars to the page
strip_tags: Removing html tags within a string
ucwords: Removing html tags within a string



 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
String Functions
htmlspecialchars
md5 hash
nl2br
Random string
strip_tags
str_replace
str_ireplace
strlen
strrev
stristr
split
substr
substr_count
str_repeat
strtolower
strcasecmp
strcmp
str_pad
trim
ucwords
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.