Jump to content

Problem with parsing script - file_get_contents returns only last result


Mikos

Recommended Posts

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();

?>

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.