Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Preg_match_all and Regex for emails

    I've got a text file on my computer that is basically a huge amount of emails crammed together with paragraphs of text about each one.

    I thought, shoot, I should preg_match_all this since i only need my emails and so I tried but my regex skills are noob level. This code below just shoots out empty arrays: Array ( [0] => Array ( ) [1] => Array ( ) ) . Anyone help?

    PHP Code:
        $email_regex    "/(\w+?@\w+?\x2E.+)/";
        
    $text_file =  "C:\Program Files\Email_Files\1.txt"
        
    $html_page file_get_contents($text_file);
            
        
    preg_match_all($email_regex$html_page$new_emails);
        foreach(
    $new_emails as $value)
            echo 
    print_r($value) . ", "

  • #2
    New Coder
    Join Date
    Nov 2010
    Posts
    12
    Thanks
    0
    Thanked 1 Time in 1 Post
    I think there's something wrong with your regexp, but the first thing I would do is be sure to view source on your output page. I suspect that since your input has HTML in it, it's not getting parsed the way you think it is, and if you're viewing the output of print_r() in a browser, the HTML is probably invisible to you.

    -Jim
    Last edited by WA; 11-25-2010 at 05:55 AM.

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm, I checked the source and it does look like an HTML page. I wouldn't think that the HTML tags would effect it?

    Code:
    <a href="">example@jimk.com</a>
    <p>Jim S. social media group</p>
    sarahmjk@yahoo.com designs websites 
    <p>list: tyuhjj@yahoo jakemonster@gmail.com example@test.com yougetThe@idea.com</p>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •