stuffradio Posted August 3, 2008 Share Posted August 3, 2008 I am working on some email thing. I'm parsing an email message, and here is what I want to do but don't know how to do it. The example message coming in should be formatted something like this: Subject: <username> Message: Username: stuffradio password: plaintext Photo caption: Cool stuff! <embedded photo> The embedded photo represents the file of the photo being uploaded. I already figured out how to strip the photo from the email and upload it. The "<username>" will be their username in the database. I want to take the argument of the Username which is stuffradio, and password which is plaintext and check the database. The password will be encrypted when checking against the database. Does anyone have any tips on what I need to do here? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 4, 2008 Share Posted August 4, 2008 Probably other ways to do it, but here is a solutions. I am not very good with Regular Expressions. <?php $str = <<<html Subject: <username> Message: username: stuffradio password: plaintext Photo caption: Cool stuff! <embedded photo> html; preg_match("#username: ([a-zA-Z0-9]+)#i",$str,$username); $username = $username[1]; preg_match("#password: ([a-zA-Z0-9]+)#i",$str,$password); $password = $password[1]; echo "Username is {$username} and password is {$password}."; ?> Quote Link to comment Share on other sites More sharing options...
stuffradio Posted August 6, 2008 Author Share Posted August 6, 2008 Thanks, it worked Quote Link to comment Share on other sites More sharing options...
discomatt Posted August 7, 2008 Share Posted August 7, 2008 NOES! Do it in one regex call! <?php $subject = 'Subject: <username> Message: Username: stuffradio password: plaintext Photo caption: Cool stuff! <embedded photo>'; preg_match_all( '/([a-z]++): (.++)/i', $subject, $matches, PREG_SET_ORDER ); # $matches[1][2] contains stuffradio # $matches[2][2] contains plaintext print_r( $matches ); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.