Jump to content

[SOLVED] preg_match_all does not return expected result


adamjblakey

Recommended Posts

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

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?

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

The source is using the decimal entity of 64, rather than the character "@":

<pre>

<?php

$email_match_regex = "/([-\w]+)(\.[-\w]+)*(?:@|&#64;)([-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>

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]+)*(?:@|&#64;)([-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.

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.