adamjblakey Posted April 2, 2008 Share Posted April 2, 2008 I am having a problem with the following, as it is not bringing back any results. <?php $email_match_regex = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$^"; for($i=1;$i<7;$i++) { $content = file_get_contents('http://www.web.co.uk/details.asp?ID='.$i); preg_match_all($email_match_regex, $content, $matches); foreach($matches[1] as $index => $value) { print $index[1]; } } ?> There is one email per id and they like this: <a href="mailto:[email protected]?Subject=This is the sbject of the email (Company-Name)&Body=Referral from www.web.co.uk%0D%0A%0D%0A" title="Send e-mail to company name"> Cheers, Adam Link to comment https://forums.phpfreaks.com/topic/99197-solved-preg_match_all-does-not-return-expected-result/ Share on other sites More sharing options...
effigy Posted April 2, 2008 Share Posted April 2, 2008 The dollar requires the email to be at the end of the string; also, I wouldn't use a metacharacter for the delimiter: /([-\w]+)(\.[-\w]+)*@([-a-z\d]+)(\.[-a-z\d]+)*(\.[a-z]{2,4})/i Link to comment https://forums.phpfreaks.com/topic/99197-solved-preg_match_all-does-not-return-expected-result/#findComment-507540 Share on other sites More sharing options...
adamjblakey Posted April 2, 2008 Author Share Posted April 2, 2008 Thank you for your reply, I have now done this: <?php $email_match_regex = "/([-\w]+)(\.[-\w]+)*@([-a-z\d]+)(\.[-a-z\d]+)*(\.[a-z]{2,4})/i"; for($i=1;$i<7;$i++) { $content = file_get_contents('http://www.uk-disco.co.uk/org-details.asp?OrgID='.$i); preg_match_all($email_match_regex, $content, $matches); foreach($matches[1] as $index => $value) { print $index[1]; } } ?> But this returns no results, any ideas? Link to comment https://forums.phpfreaks.com/topic/99197-solved-preg_match_all-does-not-return-expected-result/#findComment-507563 Share on other sites More sharing options...
effigy Posted April 2, 2008 Share Posted April 2, 2008 Loading that page redirects to http://www.uk-disco.co.uk/org-notfound.asp for me. Link to comment https://forums.phpfreaks.com/topic/99197-solved-preg_match_all-does-not-return-expected-result/#findComment-507568 Share on other sites More sharing options...
adamjblakey Posted April 2, 2008 Author Share Posted April 2, 2008 Sorry about that i did not check the id's i have tried setup this which i know has data but it does not work still: <?php $email_match_regex = "/([-\w]+)(\.[-\w]+)*@([-a-z\d]+)(\.[-a-z\d]+)*(\.[a-z]{2,4})/i"; $content = file_get_contents('http://www.uk-disco.co.uk/org-details.asp?OrgID=792'); preg_match_all($email_match_regex, $content, $matches); foreach($matches[1] as $index => $value) { print $index[1]; } ?> Cheers, Adam Link to comment https://forums.phpfreaks.com/topic/99197-solved-preg_match_all-does-not-return-expected-result/#findComment-507573 Share on other sites More sharing options...
effigy Posted April 2, 2008 Share Posted April 2, 2008 The source is using the decimal entity of 64, rather than the character "@": <pre> <?php $email_match_regex = "/([-\w]+)(\.[-\w]+)*(?:@|@)([-a-z\d]+)(\.[-a-z\d]+)*(\.[a-z]{2,4})/i"; $content = file_get_contents('http://www.uk-disco.co.uk/org-details.asp?OrgID=792'); preg_match_all($email_match_regex, $content, $matches); print_r($matches); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/99197-solved-preg_match_all-does-not-return-expected-result/#findComment-507577 Share on other sites More sharing options...
adamjblakey Posted April 2, 2008 Author Share Posted April 2, 2008 Thank you very much for that, just one last thing, how would i go about just the email address? I tried <?php $email_match_regex = "/([-\w]+)(\.[-\w]+)*(?:@|@)([-a-z\d]+)(\.[-a-z\d]+)*(\.[a-z]{2,4})/i"; $content = file_get_contents('http://www.uk-disco.co.uk/org-details.asp?OrgID=792'); preg_match_all($email_match_regex, $content, $matches); print $matches[0]; ?> but did not seem to work. Link to comment https://forums.phpfreaks.com/topic/99197-solved-preg_match_all-does-not-return-expected-result/#findComment-507585 Share on other sites More sharing options...
effigy Posted April 2, 2008 Share Posted April 2, 2008 print_r shows the layout of the array: $matches[0][0]; Link to comment https://forums.phpfreaks.com/topic/99197-solved-preg_match_all-does-not-return-expected-result/#findComment-507625 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.