check text file for email address... need help

Thread Solved

Join Date: Jun 2008
Posts: 62
Reputation: PomonaGrange is an unknown quantity at this point 
Solved Threads: 3
PomonaGrange PomonaGrange is offline Offline
Junior Poster in Training

check text file for email address... need help

 
0
  #1
Dec 7th, 2008
Hi all. I am having a little trouble trying to get a small script to work. What I am trying to do is create a page to use with DADA mail mailing list software.
I would like this page to search through the DADA mail text file of email address and find if an email specified with a GET variable is in the file.
With one option selected, it would be able to delete it or with another option, if not in the list, add an email to it. I think I can figure out the last one, but I am having difficulties with searching the file. Any suggestions.

Here's what I tried

  1. <?php
  2. $email = $_GET['email'];
  3.  
  4. $file = "../dada_files/pomona.list";
  5.  
  6. $fh = fopen($file, "r");
  7. $string = fread($fh, filesize($file));
  8. fclose($fh);
  9.  
  10. preg_match_all($email, $string, $out);
  11. echo $out[0][0] . ", " . $out[0][1] . "\n";
  12.  
  13. ?>

and I got this error:
Warning: preg_match_all() [function.preg-match-all]: Delimiter must not be alphanumeric or backslash in /read_test.php on line 10
There are alot of people smarter than me, BUT at least I try to be of some help. Of coarse I'm not perfect, I need help too.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: check text file for email address... need help

 
0
  #2
Dec 8th, 2008
Originally Posted by PomonaGrange View Post
Hi all. I am having a little trouble trying to get a small script to work. What I am trying to do is create a page to use with DADA mail mailing list software.
I would like this page to search through the DADA mail text file of email address and find if an email specified with a GET variable is in the file.
With one option selected, it would be able to delete it or with another option, if not in the list, add an email to it. I think I can figure out the last one, but I am having difficulties with searching the file. Any suggestions.

Here's what I tried

  1. <?php
  2. $email = $_GET['email'];
  3.  
  4. $file = "../dada_files/pomona.list";
  5.  
  6. $fh = fopen($file, "r");
  7. $string = fread($fh, filesize($file));
  8. fclose($fh);
  9.  
  10. preg_match_all($email, $string, $out);
  11. echo $out[0][0] . ", " . $out[0][1] . "\n";
  12.  
  13. ?>

and I got this error:
Warning: preg_match_all() [function.preg-match-all]: Delimiter must not be alphanumeric or backslash in /read_test.php on line 10
If you need the email exactly as it is, you don't need to use regular expressions. Just use stristr() or stripos() which are plain string matches and are much faster. (regular expressions are very very slow in comparison)

If you do use regular expressions such as preg_match() then you need to make sure the first argument is a regular expression.

The regular expression should start and end with a delimiter. The delimiter must not be alpha-numeric or a backslash as mentioned in the error message.

Examples:

  1. "/".$email."/"

or

  1. "|".$email."|"

You will also want to make sure you escape any characters that have meaning in when in a regular expression, from the email.

eg:

  1. "|".preg_quote($email, '|')."|"

http://www.php.net/manual/en/function.preg-quote.php
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 62
Reputation: PomonaGrange is an unknown quantity at this point 
Solved Threads: 3
PomonaGrange PomonaGrange is offline Offline
Junior Poster in Training

Re: check text file for email address... need help

 
0
  #3
Dec 8th, 2008
Hey, thanks. This was the firsdt time I tried to use the preg_match function. I was trying something new but had to learn a little more. Thanks for the help.
There are alot of people smarter than me, BUT at least I try to be of some help. Of coarse I'm not perfect, I need help too.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC