Mikos Posted October 23, 2011 Share Posted October 23, 2011 Hi, it's my first post so hello to you and i hope you will be forgiving:) I've made a basic script, which takes a urls from the form(each of them is the new row) and then search each of those urls for an email. The problem is that only the email from the last url is returned. print_r("show link:". $urls[$i]."<br>"); shows all urls in the form, but the print_r("show current_url:". $current_url); shows only the last one. <?php $urls = explode("\n", $_POST['urls']); $db = new mysqli('localhost', 'root', 'root', 'urls'); if (mysqli_connect_errno()) { echo 'Błąd: '; exit; } for ($i=0; $i<count($urls); $i++){ print_r("show link:". $urls[$i]."<br>"); $current_url = file_get_contents($urls[$i]); print_r("show current_url:". $current_url); preg_match( "/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $current_url, $email);//email print_r ("show email:".$email[0]); $zapytanie = "INSERT INTO urle set adres = '$email[0]' "; $wynik = $db->query($zapytanie); } if ($wynik) { echo $db->affected_rows ."pozycji dodano."; } else { echo mysql_errno() . ":" . mysql_error() . "Wystąpił błąd przy dodawaniu urli "; } $db->close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/249632-problem-with-parsing-script-file_get_contents-returns-only-last-result/ Share on other sites More sharing options...
freelance84 Posted October 23, 2011 Share Posted October 23, 2011 So what exactly does get printed for each iteration of the for loop from "print_r("show current_url:". $current_url);"? Quote Link to comment https://forums.phpfreaks.com/topic/249632-problem-with-parsing-script-file_get_contents-returns-only-last-result/#findComment-1281538 Share on other sites More sharing options...
Mikos Posted October 23, 2011 Author Share Posted October 23, 2011 when I enter for example two urls to the form, the first "print_r("show current_url:". $current_url); is empty and for the second it shows the page(url) content(without pictures). Quote Link to comment https://forums.phpfreaks.com/topic/249632-problem-with-parsing-script-file_get_contents-returns-only-last-result/#findComment-1281543 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.