samoi Posted September 30, 2009 Share Posted September 30, 2009 Hello guys! I have users in my db, but I need to bring up only the hotmail users only and not any other users! from their emails! So I went with this but I'm stuck !: $SQL = 0 ; // the query to pull up the ALL emails! while($row = mysql_fetch_row($SQL)) {//there are emails $emails = preg_replace('/([\w-\.]+)@(hotmail).([a-zA-Z]{2,4}\.[a-zA-Z]{2,4}|[a-zA-Z]{2,4})/','\1@\2\3',$row[0]); echo $emails; } Quote Link to comment https://forums.phpfreaks.com/topic/176021-solved-getting-only-hotmail-users-emails-and-not-yahoo/ Share on other sites More sharing options...
samoi Posted September 30, 2009 Author Share Posted September 30, 2009 BTW, I only know how to deal with preg_replace! I have no idea about the complicated preg_match_all() func! Quote Link to comment https://forums.phpfreaks.com/topic/176021-solved-getting-only-hotmail-users-emails-and-not-yahoo/#findComment-927492 Share on other sites More sharing options...
corbin Posted September 30, 2009 Share Posted September 30, 2009 What do the rows coming from the query look like? Are they individual email addresses or chunks of text containing multiple? Quote Link to comment https://forums.phpfreaks.com/topic/176021-solved-getting-only-hotmail-users-emails-and-not-yahoo/#findComment-927496 Share on other sites More sharing options...
RussellReal Posted September 30, 2009 Share Posted September 30, 2009 SELECT * FROM table WHERE LOWER(email) REGEXP '[^@]+@hotmail.com$' Quote Link to comment https://forums.phpfreaks.com/topic/176021-solved-getting-only-hotmail-users-emails-and-not-yahoo/#findComment-927505 Share on other sites More sharing options...
.josh Posted September 30, 2009 Share Posted September 30, 2009 don't even need sql regex... select * from table where email like '%@hotmail.com' Quote Link to comment https://forums.phpfreaks.com/topic/176021-solved-getting-only-hotmail-users-emails-and-not-yahoo/#findComment-927713 Share on other sites More sharing options...
.josh Posted September 30, 2009 Share Posted September 30, 2009 BTW, I only know how to deal with preg_replace! I have no idea about the complicated preg_match_all() func! all of the preg_xxxx functions use the same pcre regex engine. If anything, preg_replace is the more complicated one, as it allows you to eval the replacement. Quote Link to comment https://forums.phpfreaks.com/topic/176021-solved-getting-only-hotmail-users-emails-and-not-yahoo/#findComment-927716 Share on other sites More sharing options...
RussellReal Posted September 30, 2009 Share Posted September 30, 2009 don't even need sql regex... select * from table where email like '%@hotmail.com' well, obviously, but this is a regex forum so I tried to keep up Quote Link to comment https://forums.phpfreaks.com/topic/176021-solved-getting-only-hotmail-users-emails-and-not-yahoo/#findComment-927719 Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 The OP didn't specify they wanted Hotmail.com e-mail addresses, they specified Hotmail addresses (which I assume would include .co.uk and any other variants, especially looking at the OPs Regex). Obviously you could use SELECT * FROM TABLE WHERE `email` LIKE '%hotmail%', but this would match an email address of hotmail_sucks@yahoo.com (prepare to be found by a spambot crawler if you own that address), which I assume is not wanted. Regex certainly seems the way forward. Quote Link to comment https://forums.phpfreaks.com/topic/176021-solved-getting-only-hotmail-users-emails-and-not-yahoo/#findComment-927747 Share on other sites More sharing options...
RussellReal Posted September 30, 2009 Share Posted September 30, 2009 The OP didn't specify they wanted Hotmail.com e-mail addresses, they specified Hotmail addresses (which I assume would include .co.uk and any other variants, especially looking at the OPs Regex). Obviously you could use SELECT * FROM TABLE WHERE `email` LIKE '%hotmail%', but this would match an email address of hotmail_sucks@yahoo.com (prepare to be found by a spambot crawler if you own that address), which I assume is not wanted. Regex certainly seems the way forward. RIGHT ON SELECT * FROM table WHERE email REGEXP '[^@]+?@hotmail\.[a-z.]{2,5}' Quote Link to comment https://forums.phpfreaks.com/topic/176021-solved-getting-only-hotmail-users-emails-and-not-yahoo/#findComment-927750 Share on other sites More sharing options...
abazoskib Posted September 30, 2009 Share Posted September 30, 2009 don't even need sql regex... select * from table where email like '%@hotmail.com' That's exactly what I use, but would regex be faster in MySQL? Quote Link to comment https://forums.phpfreaks.com/topic/176021-solved-getting-only-hotmail-users-emails-and-not-yahoo/#findComment-927754 Share on other sites More sharing options...
abazoskib Posted September 30, 2009 Share Posted September 30, 2009 The OP didn't specify they wanted Hotmail.com e-mail addresses, they specified Hotmail addresses (which I assume would include .co.uk and any other variants, especially looking at the OPs Regex). Obviously you could use SELECT * FROM TABLE WHERE `email` LIKE '%hotmail%', but this would match an email address of hotmail_sucks@yahoo.com (prepare to be found by a spambot crawler if you own that address), which I assume is not wanted. Regex certainly seems the way forward. RIGHT ON SELECT * FROM table WHERE email REGEXP '[^@]+?@hotmail\.[a-z.]{2,5}' That returns ERROR 1139 (42000): Got error 'repetition-operator operand invalid' from regexp Quote Link to comment https://forums.phpfreaks.com/topic/176021-solved-getting-only-hotmail-users-emails-and-not-yahoo/#findComment-927765 Share on other sites More sharing options...
RussellReal Posted September 30, 2009 Share Posted September 30, 2009 I think maybe mysql doesn't support lazy repetition. just remove the ? from after the + Quote Link to comment https://forums.phpfreaks.com/topic/176021-solved-getting-only-hotmail-users-emails-and-not-yahoo/#findComment-927768 Share on other sites More sharing options...
RussellReal Posted September 30, 2009 Share Posted September 30, 2009 oh!! you could also do something like this: SELECT * FROM table WHERE email LIKE '%@hotmail.%' haha coz you can't have @ in your name in an email so that should always be accurate Quote Link to comment https://forums.phpfreaks.com/topic/176021-solved-getting-only-hotmail-users-emails-and-not-yahoo/#findComment-927778 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.