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
    Regular Coder
    Join Date
    Jul 2007
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Preg_Match_All Question

    Hi I have a Google Checkout script that automatically logs info into a .log file. I want to make it easier for myself to view any email address' that might be there.

    I know the method is preg_match_all after doing some google searching, I'm just not sure of the syntax.

    Thanks so much for your help.

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Depending on the format of the log, it might be easier to use something like explode rather than a regex for this. can you give the format of the log file?

    Otherwise, here's the preg_match_all manual page
    http://uk.php.net/manual/en/function.preg-match-all.php
    and here's some regexes for email addresses
    http://regexlib.com/DisplayPatterns....0&categoryId=1
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey, thanks for responding.

    I'm still throughly confused

    Code:
    <?php
    
    	$addr_spec = '([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
    			'\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|\\x22([^\\x0d'.
    			'\\x22\\x5c\\x80-\\xff]|\\x5c[\\x00-\\x7f])*\\x22)'.
    			'(\\x2e([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e'.
    			'\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|'.
    			'\\x22([^\\x0d\\x22\\x5c\\x80-\\xff]|\\x5c\\x00'.
    			'-\\x7f)*\\x22))*\\x40([^\\x00-\\x20\\x22\\x28'.
    			'\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d'.
    			'\\x7f-\\xff]+|\\x5b([^\\x0d\\x5b-\\x5d\\x80-\\xff'.
    			']|\\x5c[\\x00-\\x7f])*\\x5d)(\\x2e([^\\x00-\\x20'.
    			'\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40'.
    			'\\x5b-\\x5d\\x7f-\\xff]+|\\x5b([^\\x0d\\x5b-'.
    			'\\x5d\\x80-\\xff]|\\x5c[\\x00-\\x7f])*\\x5d))*';
    
    $email = "real@email.com - notavalid.email";
    
    	$output = preg_match_all("!^$addr_spec$!", $email);
    
    echo $output;
    
    ?>
    I'm getting some wild expression errors on this one.
    Last edited by theflyingminstr; 02-19-2010 at 08:09 PM.


  •  

    Posting Permissions

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