943,879 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2197
  • PHP RSS
Dec 7th, 2008
0

check text file for email address... need help

Expand 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

php Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008
Dec 8th, 2008
0

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

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

php Syntax (Toggle Plain Text)
  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:

PHP Syntax (Toggle Plain Text)
  1. "/".$email."/"

or

PHP Syntax (Toggle Plain Text)
  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:

PHP Syntax (Toggle Plain Text)
  1. "|".preg_quote($email, '|')."|"

http://www.php.net/manual/en/function.preg-quote.php
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Dec 8th, 2008
0

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

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.
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP and creating a new system
Next Thread in PHP Forum Timeline: code for downloading as doc file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC