I have email marketing with all language:

<form action="email.php" method="post">
<textarea name="emails" value="emails"></textarea>
<input type="submit" value="Subscribe">
</form>
<?php $emails = $_POST["emails"];
//$email = explode/ltrim/array/string/etc ???
echo $emails;

All have mixed emails with all language:

(textarea emails)
blabla1@hotmail.com
blabla2@hotmail.de
blabla3@yahoo.com
blabla4@hotmail.es
blabla5@gmail.es
...

But how can I have with one language? example I would have only .de

(textarea emails)
blabla1@hotmail.de
blabla2@hotmail.de
blabla3@gmail.de
blabla4@yahoo.de
blabla5@gmail.de
...

Can you tell me? I am completey newbie to this.

    If by "language" you mean "top-level domain" then you'd first need to split $emails into lines (preg_split on /\s+/), and then preg_grep on /\.de$/ or whatever TLD you want to keep.

    $emails = "test@example.com test@example.de test@example.net test@example.com";
    echo "<br>preg_split";
    $emails = preg_split("/[\s,]+/", $emails);
    print_r($emails);

    //preg_split Array ( [0] => test@example.com [1] => test@example.de [2] => test@example.net [3] => test@example.com )

    $emails = "test@example.com test@example.de test@example.net test@example.com";
    echo "<br>preg_grep";
    $emails = preg_grep("/^(\d+)?\.\d+$/", $emails);
    print_r($emails);

    //preg_grep

    That wont work. Can you help me?

      You could do it with just one preg_match_all(), I suppose:

      test ="test@example.com, test@example.de, test@example.fr, test2@example.de";
      preg_match_all('/(?:^|,|\s)(\S+\.de)(?:$|,|\s)/i', $test, $matches);
      print_r($matches[1]);
      /*
      Array
        (
          [0] => test@example.de
          [1] => test2@example.de
      )
      */
      

      Add some code to make the ".de" part of the regex dynamic for whichever TLD you are looking for, and you're good to go. 🙂

       $emails = preg_grep("/^(\d+)?\.\d+$/", $emails);

      I'm not surprised that doesn't work. Where did you get that from?

        NogDog Great 😀
        can you have with more strings (, < > " ,) also? Example:

        $test ='<test@example.com>, "test@example.de", test@example.fr <test2@example.de>';
        having to do with this '/(?:^|,|\s)(\S+\.de)(?:$|,|\s)/i'

          Things get a bit messy when you try to account for all valid email formats, but maybe '/\b\w\S+\.de\b/i' would suffice as the regex?

          09:52 $ /usr/bin/php -a
          Interactive shell
          
          php > $test ='<test@example.com>, "test@example.de", test@example.fr <test2@example.de>';
          php > preg_match_all('/\b\w\S+\.de\b/i', $test, $matches);
          php > print_r($matches);
          Array
          (
              [0] => Array
                  (
                      [0] => test@example.de
                      [1] => test2@example.de
                  )
          
          )
          
          3 months later

          Weedpacket Interesting stuff to read. Keep it up.
          Links removed by Site Administrator so it doesn't look like you're spamming us. Please don't post them again.

            Write a Reply...