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
https://forums.phpfreaks.com/topic/217103-extracting-email-from-url/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.