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
$email = $_GET['email'];

$file = "../dada_files/pomona.list";

  $fh = fopen($file, "r");
  $string = fread($fh, filesize($file));
  fclose($fh);

preg_match_all($email, $string, $out);
echo $out[0][0] . ", " . $out[0][1] . "\n";

?>

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

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
$email = $_GET['email'];

$file = "../dada_files/pomona.list";

  $fh = fopen($file, "r");
  $string = fread($fh, filesize($file));
  fclose($fh);

preg_match_all($email, $string, $out);
echo $out[0][0] . ", " . $out[0][1] . "\n";

?>

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:

"/".$email."/"

or

"|".$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:

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

http://www.php.net/manual/en/function.preg-quote.php

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.