473,385 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

remove last part of email address

Is there a simple way to remove the last part of an email address using
PHP. I want to remove the @ symbol and everything to the right of it.
Any ideas?

Example:

th****@xyz.com

should be:

thomas

Thanks!

Jan 4 '07 #1
4 2039
This is one way of doing it...

$temp = explode("@", $email);
echo $temp[0];

Jan 4 '07 #2

sc******@gmail.com wrote:
Is there a simple way to remove the last part of an email address using
PHP. I want to remove the @ symbol and everything to the right of it.
Any ideas?

Example:

th****@xyz.com

should be:

thomas

Thanks!
Someone here will inevitably suggest a regex, but that's overkill:

$email = 'f**@bar.com';
$username = substr($email, 0, strpos($email, '@'));

Jan 4 '07 #3
<sc******@gmail.compíse v diskusním príspevku
news:11*********************@42g2000cwt.googlegrou ps.com...
Is there a simple way to remove the last part of an email address using
PHP. I want to remove the @ symbol and everything to the right of it.
Any ideas?

Example:

th****@xyz.com

should be:

thomas
$email = preg_replace('/^(.+?)\@.+$/', '$1', $email);
--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Jan 4 '07 #4
matturbanowski "explode" option worked great. Thanks for everyone's
input.
Petr Vileta wrote:
<sc******@gmail.compíse v diskusním príspevku
news:11*********************@42g2000cwt.googlegrou ps.com...
Is there a simple way to remove the last part of an email address using
PHP. I want to remove the @ symbol and everything to the right of it.
Any ideas?

Example:

th****@xyz.com

should be:

thomas
$email = preg_replace('/^(.+?)\@.+$/', '$1', $email);
--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Jan 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
12
by: laurenq uantrell | last post by:
Is there an easy way to loop through all rows and remove all international alphabet characters from a column in a table, for example remove German umlauts "ü" and convert them to a simple "u"....
2
by: Johm | last post by:
I need some help in finding a way to remove the filter from the previous command. I open the report from a form where i have option group called Office.Depending on the option in the option...
6
by: ebc | last post by:
Hi, I have written a function that removes double entries from a sorted array. See the structures typedef struct tagRECR { char name;
4
by: rdi | last post by:
Why does the following NOT remove the items from the ListView? I need to remove all the items and re-build the LV based on new information. Thanks. -- RDI (remove the exclamation from...
7
by: Susan Mackay | last post by:
I have a data table that is connected to a database table with a data adapter in the 'standard' manner. However I want to be able to remove selected rows from the data table (i.e. no longer...
16
by: sangram | last post by:
how to delete last node of a Linked list if you only know the address of last node. thanks sangram
3
by: shalini jain | last post by:
Hi all, I dont know much of PERL so i m facing a problem in trying to remove the variable length of word from the string. I have written a code for it. Please guide me whether i will get the...
10
by: Mike Copeland | last post by:
I have data I need to normalize - it's "name" data. For example, I have the following: "Watts, J.C." I wish to (1) parse the "first name" ("J.C.") and adjust it to "JC". Essentially, I want to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.