PHP Classes
elePHPant
Icontem

Importing CVS Files

Recommend this page to a friend!

      PHP Mailing List Sanitizer  >  All threads  >  Importing CVS Files  >  (Un) Subscribe thread alerts  
Subject:Importing CVS Files
Summary:Many not only use commas
Messages:7
Author:Terry Woody
Date:2017-12-28 20:59:00
 

  1. Importing CVS Files   Reply   Report abuse  
Terry Woody - 2017-12-28 20:59:00
This is very useful script!

Many autoreponder services export with format like:

email,firstname,lastname,address,phone,notes,ip,time
noreply@gmail.com,john,doe,,,
noreply1@gmail.com,Jane,Doe,,,

I have been unsuccessful in getting exports formatted like above to work. Is it safe to assume that one cannot use standard exports from services like Getresponse and Aweber?

The list sanitizer script will only work if your CVS is a list of mails only separated by a comma?

Thank you!

  2. Re: Importing CVS Files   Reply   Report abuse  
zinsou A.A.E.Mo´se - 2017-12-28 23:31:56 - In reply to message 1 from Terry Woody
Hi
this may help you :
<?php

function findEmails($string){
$email_regular_expression="([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,24}";
preg_match_all('/'.str_replace('/', '\\/', $email_regular_expression).'/', $string,$matches);
return $matches[0];
}

$string="email,firstname,lastname,address,phone,notes,ip,time
noreply@gmail.com,john,doe,,,
noreply1@gmail.com,Jane,Doe,,,";
echo '<pre>';
print_r(findEmails($string));
/*result :
Array
(
[0] => noreply@gmail.com
[1] => noreply1@gmail.com
)
*/
?>
so you may from there use the output of this function to fill the php mailinglist sanitizer method "EmailChecker::ARprocess"
as shown in the example file and all will be done

your complete script may be

<?php
require_once('EmailChecker.class.php');
function findEmails($string){
$email_regular_expression="([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,24}";
preg_match_all('/'.str_replace('/', '\\/', $email_regular_expression).'/', $string,$matches);
return $matches[0];
}
$var=file_get_contents('yourfile.csv');//get the content from your file in any plain text format;
$emails=findEmails($var);//retrieve the emails
$x=new EmailChecker(); // create your checker object
$x->ARprocess($ar,time().'.csv'));//call the array sanitizer...sanitize and save to timestamp.csv(you can choose your own name provided that the file doesn't exist)
?>

  3. Re: Importing CVS Files   Reply   Report abuse  
zinsou A.A.E.Mo´se - 2017-12-28 23:35:52 - In reply to message 2 from zinsou A.A.E.Mo´se
$x->ARprocess($var,time().'.csv'));//call the array sanitizer...sanitize and save to timestamp.csv(you can choose your own name provided that the file doesn't exist)
?>
instead of
$x->ARprocess($ar,time().'.csv'));//call the array sanitizer...sanitize and save to timestamp.csv(you can choose your own name provided that the file doesn't exist)
?>

  4. Re: Importing CVS Files   Reply   Report abuse  
zinsou A.A.E.Mo´se - 2017-12-28 23:44:58 - In reply to message 3 from zinsou A.A.E.Mo´se
sorry but it is :

$x->ARprocess($emails,time().'.csv'));//call the array sanitizer...sanitize and save to timestamp.csv(you can choose your own name provided that the file doesn't exist)
?>

instead of

$x->ARprocess($var,time().'.csv'));//call the array sanitizer...sanitize and save to timestamp.csv(you can choose your own name provided that the file doesn't exist)
?>

  5. Re: Importing CVS Files   Reply   Report abuse  
Terry Woody - 2017-12-29 00:43:21 - In reply to message 4 from zinsou A.A.E.Mo´se
Thank you for reply and mods. I will try them in the morning and let you know how it goes.

Appreciate your assistance sir.

  6. Re: Importing CVS Files   Reply   Report abuse  
Terry Woody - 2017-12-29 16:49:18 - In reply to message 4 from zinsou A.A.E.Mo´se
Yes, your suggested mods work great! I thank you for help.

If I could make one suggestion: Build in ability to pause (sleep/unsleep) the script so larger files can be loaded. Currently the script will time out based on server settings.

Thank you again,

TW

  7. Re: Importing CVS Files   Reply   Report abuse  
zinsou A.A.E.Mo´se - 2017-12-29 18:57:31 - In reply to message 6 from Terry Woody
Hi
Happy to help. For the timeout issue you can prepend to the code i gave here set_time_limit(0);