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:adam@email.com?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
Share on other sites

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
Share on other sites

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
Share on other sites

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>

Link to comment
Share on other sites

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.

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.