preg_match_all does not return expected result

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adamjblakey
    New Member
    • Jan 2008
    • 133

    preg_match_all does not return expected result

    Hi,

    I seem i seem to have a problem with this:[PHP]
    for($i=1;$i<7;$ i++) {
    $content = file_get_conten ts('http://www.web.co.uk/d.asp?ID='.$i);
    preg_match_all( $email_match_re gex, $content, $matches);
    foreach($matche s[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_reg ex in /home/ee/public_html/test.php on line 11

    Any Ideas?
  • msenyoo
    New Member
    • Mar 2008
    • 1

    #2
    Originally posted by adamjblakey
    Hi,

    I seem i seem to have a problem with this:

    [PHP]
    for($i=1;$i<7;$ i++) {

    $content = file_get_conten ts('http://www.web.co.uk/d.asp?ID='.$i);
    preg_match_all( $email_match_re gex, $content, $matches);

    foreach($matche s[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_reg ex in /home/ee/public_html/test.php on line 11

    Any Ideas?

    HI
    assign reg expression value to $email_match_re gex

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Originally posted by adamjblakey
      Hi,

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

      Notice: Undefined variable: email_match_reg ex in /home/ee/public_html/test.php on line 11
      Hey there adam!

      PHP is saying you haven't got a variable named email_match_reg ex?

      Check to see if you do!
      Regards.

      Comment

      • aktar
        New Member
        • Jul 2006
        • 105

        #4
        Hi Adam,

        The problem is in the follwoing line:
        [PHP]$content = file_get_conten ts('http://www.web.co.uk/d.asp?ID='.$i);[/PHP]file_get_conten ts() will fetch raw data, ie the page will not be parsed.
        And becasuse its not parsed, the filename param given must match to the filename exactly.

        Consequently, because $content is empty, you get a whole load of problem further down your script.

        My question to you: should you be trying to take data from other websites?

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          Originally posted by aktar
          Hi Adam,

          The problem is in the follwoing line:
          [PHP]$content = file_get_conten ts('http://www.web.co.uk/d.asp?ID='.$i);[/PHP]
          file_get_conten ts() will fetch raw data, ie the page will not be parsed. And becasuse its not parsed, the filename param given must match to the filename exactly.

          Consequently, because $content is empty, you get a whole load of problem further down your script.

          My question to you: should you be trying to take data from other websites?
          This is absolutely not true!

          The error originates in the absence of the regular expression pattern variable in line 11. Since there is no result, there is also no $matches variable, resulting in the error on line 13.

          The content of variable $content has nothing to do with this. Even if it is empty the preg_match_all results in an array containing one or more empty arrays.

          Originally posted by aktar
          My question to you: should you be trying to take data from other websites?
          And please: no missionaries. This is not the place to question our members on their reason for using a pretty-standard PHP function. There is no indication whatsoever that it is morally unjust or illegal what our member adamjblakey is doing! So don't even hint at that!

          Ronald
          Last edited by ronverdonk; Mar 29 '08, 11:51 PM. Reason: add extra text

          Comment

          • adamjblakey
            New Member
            • Jan 2008
            • 133

            #6
            Thank you for that ronverdonk, i have now done this based on your comments, which does not bring any errors back but does not bring any results but i know there should be.

            [PHP]<?php

            $email_match_re gex = "^([_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_conten ts('http://www.web.co.uk/details.asp?ID= '.$i);

            preg_match_all( $email_match_re gex, $content, $matches);

            foreach($matche s[1] as $index => $value) {

            print $index[1];

            }

            }

            ?>[/PHP]

            Comment

            • ronverdonk
              Recognized Expert Specialist
              • Jul 2006
              • 4259

              #7
              Please explain what the reg exp is supposed to filter.

              Ronald

              Comment

              • adamjblakey
                New Member
                • Jan 2008
                • 133

                #8
                There will be one email per id and they like this:

                Code:
                <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">
                I just need the email address e.g.: adam@email.com

                Comment

                Working...