dflow Posted May 17, 2011 Share Posted May 17, 2011 i have a garbled list of email details in html how can i parse all the emails between: To: [email protected] Subject: thanks Quote Link to comment https://forums.phpfreaks.com/topic/236628-parsing-help/ Share on other sites More sharing options...
dflow Posted May 17, 2011 Author Share Posted May 17, 2011 regex 'to: (.*) Subject:' so get_file_content(); $regex='to: (.*) Subject:' Quote Link to comment https://forums.phpfreaks.com/topic/236628-parsing-help/#findComment-1216457 Share on other sites More sharing options...
dflow Posted May 17, 2011 Author Share Posted May 17, 2011 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/236628-parsing-help/#findComment-1216465 Share on other sites More sharing options...
fugix Posted May 17, 2011 Share Posted May 17, 2011 might want to try this $file = file_get_contents("http://localhost/TA/nw.html"); preg_match_all('/To:(.*?)Subject:/i', $file, $matches); Quote Link to comment https://forums.phpfreaks.com/topic/236628-parsing-help/#findComment-1216466 Share on other sites More sharing options...
dflow Posted May 18, 2011 Author Share Posted May 18, 2011 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" Quote Link to comment https://forums.phpfreaks.com/topic/236628-parsing-help/#findComment-1216907 Share on other sites More sharing options...
dflow Posted May 18, 2011 Author Share Posted May 18, 2011 might want to try this $file = file_get_contents("http://localhost/TA/nw.html"); preg_match_all('/To:(.*?)Subject:/i', $file, $matches); with this im getting 23 as a result that's it?? Quote Link to comment https://forums.phpfreaks.com/topic/236628-parsing-help/#findComment-1216910 Share on other sites More sharing options...
dflow Posted May 18, 2011 Author Share Posted May 18, 2011 bump why am i getting 23 as an output? Quote Link to comment https://forums.phpfreaks.com/topic/236628-parsing-help/#findComment-1217210 Share on other sites More sharing options...
pornophobic Posted May 18, 2011 Share Posted May 18, 2011 What is the output if you put var_dump($matches); after preg_match_all? Quote Link to comment https://forums.phpfreaks.com/topic/236628-parsing-help/#findComment-1217242 Share on other sites More sharing options...
dflow Posted May 19, 2011 Author Share Posted May 19, 2011 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:[email protected]">[email protected]> Subject:" [6]=> string(62) "to:[email protected]">[email protected] Subject:" [7]=> string(38) "to:references:date:message-id:subject:" [8]=> string(38) "to:references:date:message-id:subject:" [9]=> string(62) "to:[email protected]">[email protected]> Subject:" [10]=> string(62) "to:[email protected]">[email protected] Subject:" [11]=> string(38) "to:references:date:message-id:subject:" [12]=> string(62) "to:[email protected]">[email protected]> Subject:" [13]=> string(38) "to:references:date:message-id:subject:" [14]=> string(62) "to:[email protected]">[email protected] 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:[email protected]">[email protected]> Subject:" [19]=> string(62) "to:[email protected]">[email protected] Subject:" [20]=> string(38) "to:references:date:message-id:subject:" [21]=> string(38) "to:references:date:message-id:subject:" [22]=> string(62) "to:[email protected]">[email protected] 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) "[email protected]">[email protected]> " [6]=> string(51) "[email protected]">[email protected] " [7]=> string(27) "references:date:message-id:" [8]=> string(27) "references:date:message-id:" [9]=> string(51) "[email protected]">[email protected]> " [10]=> string(51) "[email protected]">[email protected] " [11]=> string(27) "references:date:message-id:" [12]=> string(51) "[email protected]">[email protected]> " [13]=> string(27) "references:date:message-id:" [14]=> string(51) "[email protected]">[email protected] " [15]=> string(27) "references:date:message-id:" [16]=> string(27) "references:date:message-id:" [17]=> string(27) "references:date:message-id:" [18]=> string(51) "[email protected]">[email protected]> " [19]=> string(51) "[email protected]">[email protected] " [20]=> string(27) "references:date:message-id:" [21]=> string(27) "references:date:message-id:" [22]=> string(51) "[email protected]">[email protected] " } } 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:[email protected]">[email protected]> Subject: [6] => to:[email protected]">[email protected] Subject: [7] => to:references:date:message-id:subject: [8] => to:references:date:message-id:subject: [9] => to:[email protected]">[email protected]> Subject: [10] => to:[email protected]">[email protected] Subject: [11] => to:references:date:message-id:subject: [12] => to:[email protected]">[email protected]> Subject: [13] => to:references:date:message-id:subject: [14] => to:[email protected]">[email protected] Subject: [15] => to:references:date:message-id:subject: [16] => to:references:date:message-id:subject: [17] => to:references:date:message-id:subject: [18] => to:[email protected]">[email protected]> Subject: [19] => to:[email protected]">[email protected] Subject: [20] => to:references:date:message-id:subject: [21] => to:references:date:message-id:subject: [22] => to:[email protected]">[email protected] 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] => [email protected]">[email protected]> [6] => [email protected]">[email protected] [7] => references:date:message-id: [8] => references:date:message-id: [9] => [email protected]">[email protected]> [10] => [email protected]">[email protected] [11] => references:date:message-id: [12] => [email protected]">[email protected]> [13] => references:date:message-id: [14] => [email protected]">[email protected] [15] => references:date:message-id: [16] => references:date:message-id: [17] => references:date:message-id: [18] => [email protected]">[email protected]> [19] => [email protected]">[email protected] [20] => references:date:message-id: [21] => references:date:message-id: [22] => [email protected]">[email protected] ) ) after preg_match_all? Quote Link to comment https://forums.phpfreaks.com/topic/236628-parsing-help/#findComment-1217436 Share on other sites More sharing options...
pornophobic Posted May 19, 2011 Share Posted May 19, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/236628-parsing-help/#findComment-1217468 Share on other sites More sharing options...
dflow Posted May 23, 2011 Author Share Posted May 23, 2011 still need help parsing this thanks Quote Link to comment https://forums.phpfreaks.com/topic/236628-parsing-help/#findComment-1219061 Share on other sites More sharing options...
dflow Posted May 23, 2011 Author Share Posted May 23, 2011 why is this invalid???? [coe] <?php $getemails=preg_match ('/(To:)(.*)/', $file, $matchesarray); foreach($getemails as $getemail) { echo $matchesarray[0];} ?> [.code] Quote Link to comment https://forums.phpfreaks.com/topic/236628-parsing-help/#findComment-1219081 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.