mjahkoh Posted June 6, 2011 Share Posted June 6, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/238560-read-email-from-website/ Share on other sites More sharing options...
dougjohnson Posted June 6, 2011 Share Posted June 6, 2011 $homepage = file_get_contents('http://www.example.com/'); Then parse $homepage, this would be one way to do this... I think Quote Link to comment https://forums.phpfreaks.com/topic/238560-read-email-from-website/#findComment-1225923 Share on other sites More sharing options...
Maq Posted June 6, 2011 Share Posted June 6, 2011 In the future, please place tags around your code. Quote Link to comment https://forums.phpfreaks.com/topic/238560-read-email-from-website/#findComment-1225972 Share on other sites More sharing options...
xyph Posted June 6, 2011 Share Posted June 6, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238560-read-email-from-website/#findComment-1225975 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.