Jump to content

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/117996-solved-regex-validation/
Share on other sites

Probably other ways to do it, but here is a solutions. I am not very good with Regular Expressions. :P

 

<?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}.";

?>

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 );

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.