Jump to content

parsing help


dflow

Recommended Posts

ok some code im playing with

 

<?php

$file = file_get_contents("http://localhost/TA/nw.html");


$regex="/To: (.*) Subject:/";
$getemails=preg_match_all($regex, $file,$email);

foreach($getemails as $getemail) {
   echo $getemail;


}

?>

Link to comment
Share on other sites

might want to try this

$file = file_get_contents("http://localhost/TA/nw.html");
preg_match_all('/To:(.*?)Subject:/i', $file, $matches);

i set an array with

$getemails=array();

why do i get "Invalid argument supplied for foreach"

 

 

Link to comment
Share on other sites

What is the output if you put

var_dump($matches);

 

23array(2) { [0]=> array(23) { [0]=> string(38) "to:references:date:message-id:subject:" [1]=> string(38) "to:references:date:message-id:subject:" [2]=> string(38) "to:references:date:message-id:subject:" [3]=> string(38) "to:references:date:message-id:subject:" [4]=> string(38) "to:references:date:message-id:subject:" [5]=> string(62) "to:info@example.com">info@example.com>
Subject:" [6]=> string(62) "to:info@example.com">info@example.com
Subject:" [7]=> string(38) "to:references:date:message-id:subject:" [8]=> string(38) "to:references:date:message-id:subject:" [9]=> string(62) "to:info@example.com">info@example.com>
Subject:" [10]=> string(62) "to:info@example.com">info@example.com
Subject:" [11]=> string(38) "to:references:date:message-id:subject:" [12]=> string(62) "to:info@example.com">info@example.com>
Subject:" [13]=> string(38) "to:references:date:message-id:subject:" [14]=> string(62) "to:info@example.com">info@example.com
Subject:" [15]=> string(38) "to:references:date:message-id:subject:" [16]=> string(38) "to:references:date:message-id:subject:" [17]=> string(38) "to:references:date:message-id:subject:" [18]=> string(62) "to:info@example.com">info@example.com>
Subject:" [19]=> string(62) "to:info@example.com">info@example.com
Subject:" [20]=> string(38) "to:references:date:message-id:subject:" [21]=> string(38) "to:references:date:message-id:subject:" [22]=> string(62) "to:info@example.com">info@example.com
Subject:" } [1]=> array(23) { [0]=> string(27) "references:date:message-id:" [1]=> string(27) "references:date:message-id:" [2]=> string(27) "references:date:message-id:" [3]=> string(27) "references:date:message-id:" [4]=> string(27) "references:date:message-id:" [5]=> string(51) "info@example.com">info@example.com>
" [6]=> string(51) "info@example.com">info@example.com
" [7]=> string(27) "references:date:message-id:" [8]=> string(27) "references:date:message-id:" [9]=> string(51) "info@example.com">info@example.com>
" [10]=> string(51) "info@example.com">info@example.com
" [11]=> string(27) "references:date:message-id:" [12]=> string(51) "info@example.com">info@example.com>
" [13]=> string(27) "references:date:message-id:" [14]=> string(51) "info@example.com">info@example.com
" [15]=> string(27) "references:date:message-id:" [16]=> string(27) "references:date:message-id:" [17]=> string(27) "references:date:message-id:" [18]=> string(51) "info@example.com">info@example.com>
" [19]=> string(51) "info@example.com">info@example.com
" [20]=> string(27) "references:date:message-id:" [21]=> string(27) "references:date:message-id:" [22]=> string(51) "info@example.com">info@example.com
" } } Array ( [0] => Array ( [0] => to:references:date:message-id:subject: [1] => to:references:date:message-id:subject: [2] => to:references:date:message-id:subject: [3] => to:references:date:message-id:subject: [4] => to:references:date:message-id:subject: [5] => to:info@example.com">info@example.com>
Subject: [6] => to:info@example.com">info@example.com
Subject: [7] => to:references:date:message-id:subject: [8] => to:references:date:message-id:subject: [9] => to:info@example.com">info@example.com>
Subject: [10] => to:info@example.com">info@example.com
Subject: [11] => to:references:date:message-id:subject: [12] => to:info@example.com">info@example.com>
Subject: [13] => to:references:date:message-id:subject: [14] => to:info@example.com">info@example.com
Subject: [15] => to:references:date:message-id:subject: [16] => to:references:date:message-id:subject: [17] => to:references:date:message-id:subject: [18] => to:info@example.com">info@example.com>
Subject: [19] => to:info@example.com">info@example.com
Subject: [20] => to:references:date:message-id:subject: [21] => to:references:date:message-id:subject: [22] => to:info@example.com">info@example.com
Subject: ) [1] => Array ( [0] => references:date:message-id: [1] => references:date:message-id: [2] => references:date:message-id: [3] => references:date:message-id: [4] => references:date:message-id: [5] => info@example.com">info@example.com>
[6] => info@example.com">info@example.com
[7] => references:date:message-id: [8] => references:date:message-id: [9] => info@example.com">info@example.com>
[10] => info@example.com">info@example.com
[11] => references:date:message-id: [12] => info@example.com">info@example.com>
[13] => references:date:message-id: [14] => info@example.com">info@example.com
[15] => references:date:message-id: [16] => references:date:message-id: [17] => references:date:message-id: [18] => info@example.com">info@example.com>
[19] => info@example.com">info@example.com
[20] => references:date:message-id: [21] => references:date:message-id: [22] => info@example.com">info@example.com
) ) 

after preg_match_all?

Link to comment
Share on other sites

 

why do i get "Invalid argument supplied for foreach"

 

preg_match_all creates an array and populates it with data for you.

 

You are getting 23.

Are you commenting out everything that you added in?

Is there a count() somewhere in the script?

 

It looks like you are performing regex searches on the plain text output you see in a browser and you had said that it is in HTML. Could you either post the source of your email file, a line of the source in that file or send it to me through PM?

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.