1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP Script: How to grab e-mails from code.

Discussion in 'PHP & Perl' started by markhansavon, Dec 4, 2008.

  1. markhansavon

    markhansavon Newbie

    Joined:
    Dec 3, 2008
    Messages:
    16
    Likes Received:
    0
    I'm stuck on a pretty simple PHP problem. Basically, I want to know how to grab a string at a certain point in the page source code. (where the e-mail is). It is a SMF (forum), soI've got something like this:

    I need to first be able to cut it from the above down to this:

    I already know how to do this part by using the strstr command (finding everything after mailto:.

    Now I would like to know how to delete everything after the 'M', but I just can't find the command that would work.

    If anyone could answer or lead me in the right direction, thanks ahead of time.
     
    Last edited: Dec 4, 2008
  2. chaoz

    chaoz Newbie

    Joined:
    Mar 13, 2007
    Messages:
    47
    Likes Received:
    12
    Home Page:
    Code:
    <?
    $code = '<td class="windowbg"><a href="mailto:THISISWHERETHEEMAILIS@something.com"><br /><td class="windowbg"><a href="mailto:THISISWHERETHEEMAILIS2@something.com"><br /><td class="windowbg"><a href="mailto:THISISWHERETHEEMAILIS3@something.com"><br />';
    preg_match_all('/<a href="mailto:(.*?)">/', $code, $found);
    
    print_r( $found );
    ?>
    
    have fun ;)
     
  3. markhansavon

    markhansavon Newbie

    Joined:
    Dec 3, 2008
    Messages:
    16
    Likes Received:
    0
    wooooooooowwwww :eek:

    I like the code, will use it. Thanks. ;-)

    EDIT: "$found" is an array, now, isn't it? hmm... How do I echo it out then?
     
    Last edited: Dec 5, 2008
  4. markhansavon

    markhansavon Newbie

    Joined:
    Dec 3, 2008
    Messages:
    16
    Likes Received:
    0
    Oh nvm, I've got it, you do

    echo $found[1][0];