Jump to content

Read email from Website


mjahkoh

Recommended Posts

Can someone point me in the right direction on reading email from a website where the email address is confined between two words "E-mail" & Post.

What i got below just reads one time.

 

      $handle = fopen($address, "r"); // point stream to site
      while (!feof($handle)) {
            $contents .= fread($handle, 8192); // read site into buffer
      }
      
      echo "searching site: " . $address ."<br>";

      // pick word to start reading from
      $start = "E-mail";
  $start_pos = strpos($contents, $start);  // find position of that word
      echo "Starting at: " . $start . "<br>found at location: " . $start_pos . "<br>";

      $first_trim = substr($contents, $start_pos);

      // pick word to stop reading at
      $stop = "Post";
  $stop_pos = strpos($first_trim, $stop);  // find position of that word
      echo "Stoping at: " . $stop . "<br>found at location: " . $stop_pos . "<br>";

      // cut the string before and after selected words
      $second_trim = substr($first_trim, 0, $stop_pos);

      echo "<p>" . $second_trim;
      
      fclose($handle);

Link to comment
Share on other sites

You want to use a while loop to iterate through a string using strpos.

 

<?php

$string = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.';
$offset = 0;
$find = 'e';

while( ($offset = strpos($string, $find, $offset)) !== FALSE ) {

echo 'Found an e at $string['.$offset.']. It was around "'.substr($string,$offset-2,5).'"<br>';
$offset++; // Increase offset by 1 to start looking at the next character

}

?>

 

As a slower alternative, you could use preg_match_all, and have a static string as the expression. The code would be more simple, but less efficient.

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.