Jump to content

Extracting Email from URL


foxcore

Recommended Posts

HI guys,

 

I'm quite new to php, and I'm really struggling to get this right. I just cant get it to work properly.

 

Im trying to extract email from a list of URLS. I have currently got it to work with 1 URL at a time, but I am needing to as to how I can pass multiple URLS at once, either from a csv or just pasting them into the input.

any help would be much appriciated. here is my current code:

 

<?php

 

 

 

$the_url = isset($_REQUEST['url']) ? htmlspecialchars($_REQUEST['url']) : '';

?>

 

<form method="post">

  Please enter full URL of the page to parse (including http://):<br />

  <textarea name="url" cols="100" rows="10"><?php echo $the_url;  ?></textarea>

  <br />

 

  <input type="submit" value="Get Emails" />

</form>

 

<?php

if (isset($_REQUEST['url']) && !empty($_REQUEST['url'])) {

  // fetch data from specified url

  $text = file_get_contents($_REQUEST['url']);

}

elseif (isset($_REQUEST['text']) && !empty($_REQUEST['text'])) {

  // get text from text area

  $text = $_REQUEST['text'];

}

 

// parse emails

if (!empty($text)) {

  $res = preg_match_all(

    "/[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i",

    $text,

    $matches

  );

 

  if ($res) {

    foreach(array_unique($matches[0]) as $email) {

      echo $email . "<br />";

    }

  }

  else {

    echo "No emails found.";

  }

}

 

?>

Link to comment
Share on other sites

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.