Whats wrong with this script?

Discussion in 'PHP' started by adamjblakey, Mar 26, 2008.

  1. #1
    Hi,

    I seem i seem to have a problem with this:

    
     
          for($i=1;$i<7;$i++) {
    
              $content = file_get_contents('http://www.web.co.uk/d.asp?ID='.$i);
      
              preg_match_all($email_match_regex, $content, $matches);
    
                      foreach($matches[1] as $index => $value) {
    
              print $index[1];   
    
              }
      
          }
    
    
    PHP:
    I am getting the following errors which i cannot fix:

    Warning: Invalid argument supplied for foreach() in /home/ee/public_html/test.php on line 13

    Notice: Undefined variable: email_match_regex in /home/ee/public_html/test.php on line 11

    Any Ideas?
     
    adamjblakey, Mar 26, 2008 IP
  2. Im The ONE

    Im The ONE Peon

    Messages:
    800
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You haven't defined a regex pattern to validate emails
    
    $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/d.asp?ID='.$i);
     
              preg_match_all($email_match_regex, $content, $matches);
    
                      foreach($matches[1] as $index => $value) {
    
              print $index[1];   
    
              }
     
          }
    
    PHP:
     
    Im The ONE, Mar 26, 2008 IP
  3. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Thank you for your reply but i am now getting this error:

    Warning: preg_match_all() [function.preg-match-all]: No ending delimiter '^' found in /home/ee/public_html/test.php on line 16

    Warning: Invalid argument supplied for foreach() in /home/ee/public_html/test.php on line 18

    I though the problem might be with the $email_match_regex so i did this: $email_match_regex = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$^";

    But this then does not give any errors or results and goes to a white screen.
     
    adamjblakey, Mar 26, 2008 IP
  4. Im The ONE

    Im The ONE Peon

    Messages:
    800
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm not that good with regex lets wait for someone else to post a better pattern. are you trying to fetch data from http://www.web.co.uk/d.asp?ID=1 because this webpage does not exists
     
    Im The ONE, Mar 26, 2008 IP
  5. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #5
    Ok Thank you for trying, Anyone else?
     
    adamjblakey, Mar 28, 2008 IP
  6. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #6
    Can someone help with this?
     
    adamjblakey, Apr 2, 2008 IP
  7. NewTier

    NewTier Notable Member

    Messages:
    2,201
    Likes Received:
    196
    Best Answers:
    0
    Trophy Points:
    250
    #7

    Notice: Undefined variable: email_match_regex in /home/ee/public_html/test.php on line 11


    What that basically means is that the PHP script is searching for the content files and not finding anything useful.

    So there's nothing to replace therefore it's nulled.

    some sites don't allow the retrieval through php.

    I know from experience.
     
    NewTier, Apr 2, 2008 IP