Welcome Guest, Not a member yet? Register   Sign In
how to separat the emails that i have ??
#1

[eluser]frrose[/eluser]
hi all !

i want to ask

if I have many Email like this exo@yahoo.com;[email protected];[email protected];[email protected]


and i want to insert it in database but each email is alone in one record how ??


and i want it to be in form to use it any time i want Smile

thanks ..
#2

[eluser]gyo[/eluser]
Code:
$emails_string = "[email protected];[email protected];[email protected];[email protected]";
$emails_array = explode(";",$emails_string);

Then you just have to loop through $emails_array and insert each item into the database.

Btw... are you sure that you're not going to send spam? Tongue
#3

[eluser]frrose[/eluser]
No i won't

but Grad Student
lets say that we have an wrong email on it ?
or some of this emails dont have ;
or if tehy change the ; in new line

then how Smile ??
#4

[eluser]Thorpe Obazee[/eluser]
o.o

huh? maybe you can explain the situation?
#5

[eluser]gyo[/eluser]
To check the email addresses you can use the valid_email function.

For the second problem you should define a separator and stuck with it; if this is not possible then you can do some regular expression to search for *@*.* where the asterisks are the user, the domain and the extension.
Basically you want to search for [email protected]

Hope that helps.

gyo
#6

[eluser]frrose[/eluser]
sorry suashi ..
but i didnt understand how to solve the second problem :blank:
could you give me an example if you dont mind
#7

[eluser]gyo[/eluser]
I just found something that you could use:

Code:
<?php
/*
Snippet Name: Get Emails from Strings
Author : Hermawan Haryanto
Email : [email protected]
Homepage: http://hermawan.com
Blog : http://hermawan.codewalkers.com
*/

function get_emails ($str)
{
   $emails = array();
   preg_match_all("/\b\w+\@\w+[\.\w+]+\b/", $str, $output);
   foreach($output[0] as $email) array_push ($emails, strtolower($email));
   if (count ($emails) >= 1) return $emails;
   else return false;
}

# Here is how to use it.

# Sample string containing email addresses;
$str = "test [email protected] ha ha [email protected] bla bla [email protected]";

# Get the emails on arrays;
$emails = get_emails ($str);

# Print that arrays;
print_r ($emails);
?>

$emails will be the array containing all the addresses, so you can go through it with a loop.
#8

[eluser]frrose[/eluser]
oh that is great Smile

thank you man Smile
#9

[eluser]gyo[/eluser]
No problem, I only hope you'll not make an email spider! Tongue
#10

[eluser]frrose[/eluser]
no dont worry
i will not




Theme © iAndrew 2016 - Forum software by © MyBB