Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23

Thread: Regex extract sequence of a certain format from string

  1. #11
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That method would work fine. Just check for email when you look for email.

    However, if you want something else to automatically happen such as an "auto-reply" things get much more complicated. In my case, I am attempting to 'upload' files via email, so this should happen when the email is sent (and 'received') not the next time someone logs in.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #12
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    yeah.

    do you have any control over the mail server? I don't know anything about it, but it seems you might be able to have the mail server "ping" your upload scripts when there's a new message...? just a thought.

  3. The Following User Says Thank You to traq For This Useful Post:

    djr33 (10-08-2010)

  4. #13
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Two answers to that: at the moment, no, since I don't have it configured that way.

    In the future, it might be possible, but that would require a different language than PHP, so it wouldn't really be a "PHP" thing. Of course for the purpose that's fine. As a test for what PHP can do, it doesn't really accomplish much.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #14
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I looked into the ideas above a bit and I came up with an interesting link:
    http://harrybailey.com/2009/02/send-...-a-php-script/
    That requires cpanel, though.
    This looks like a way around it:
    http://forum.powweb.com/archive/index.php/t-63142.html
    I think you still need to install a mail server on the system though.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #15
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Everything I saw on the powweb link used cron jobs.

    Does your server not use cPanel? I wonder if other control panels wouldn't have a similar option... ::wanders off to check::

  7. #16
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Returning to this thread after a while, I'm now actually setting this up for my project.

    I'm using a cron job and checking if the subject contains a string that looks right. If so, try to 'upload'-- see if there's an attachment, validate the code, etc.


    BTW, Adrian, I missed your question earlier: no, the current host doesn't use cpanel, unfortunately.

    I'm happy with this cron job though since it does other things as well.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #17
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I asked 1&1 about "piping" emails to a script, and the initial customer service guy didn't *quite* know what I was talking about... We'll see if I can get any further.

  9. #18
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I imagine it's not something that your average host will support (at least not actively-- there might be an option somewhere). Do let me know if you figure it out though.

    With an external mail server and a cron job it's easy enough, if you can deal with the slight delay, slight inefficiency, and that the script is slow to run because it must connect to the external server-- the same sort of delays you get with FTP-- each action requires logging in again etc. (At least I imagine this is what is happening. I'm not sure how it functions at the deepest level.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #19
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    After some thorough testing, I found a flaw in the regex. Something is wrong with preg_match_all().

    If there are overlapping matches, such as '1234' where we want "3 numbers in a row" which should return 123 and 234, preg_match_all() only returns one.

    I'm posting because I'm kinda curious about why that's not working.

    I solved it using this, so there's no need to fix it, just wondering.


    Code:
    	$matches = array();
    	while (strlen($str)>=10) {
    		preg_match('/[a-fA-F0-9]{10}/', $str, $match);
    		$matches[] = $match;
    		$str = substr($str,1);
    	}
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  11. #20
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    after finding a match, preg_match_all continues searching from the end of that match (it won't look for "overlapping" matches).
    Edit:

    It seems there ought to be such a function, but I can't seem to find one right now...

    You could do it by putting preg_match() in a loop and incrementing the offset each time, for the length of the string. Not very efficient, I guess. You'd have to keep track of the match positions, as well, or you'd count some of the matches more than once.

    Last edited by traq; 11-10-2010 at 05:12 AM.

  12. The Following User Says Thank You to traq For This Useful Post:

    djr33 (11-10-2010)

Bookmarks

Posting Permissions

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