| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 
 | <?php
include('conn_sql.php');
$sexe='femme';
$document = new DOMDocument();
$document->load('https://example.com/format=xml');
mysqli_query($conn, "UPDATE users SET is_online=0 WHERE sexe='$sexe'") or die(mysqli_error($conn));
 
$xpath = new DOMXpath($document);
 
$entries = $xpath->evaluate('/*/ressources');
foreach($entries as $entry) {
    $username = $xpath->evaluate('string(username)', $entry);
    $nb_followers = $xpath->evaluate('string(num_followers)', $entry);
    $nb_likers = $xpath->evaluate('string(num_likers)', $entry);
    $description = $xpath->evaluate('string(topic_title)', $entry);
    $description = mysqli_real_escape_string($conn,$description);
    $pseudo = $xpath->evaluate('string(pseudo)', $entry);
    $pseudo = mysqli_real_escape_string($conn,$pseudo);
 
    $result = mysqli_query($conn, "SELECT username FROM users WHERE sexe='$sexe' AND username='$username'");
 
    $tags = array_map(
      function(\DOMElement $node) {
          return $node->textContent;
      },
      iterator_to_array($xpath->evaluate('tags/ressources', $entry))
    );
    if(!$row = mysqli_fetch_row($result) || $nb_followers < 100){
           mysqli_query($conn, "INSERT INTO users (sexe,username,pseudo,bio_en, bio_fr, bio_es, bio_it, bio_de, bio_pt,nb_followers,nb_likers,temp_tags_en,temp_tags_fr,temp_tags_es,temp_tags_it,temp_tags_de,temp_tags_pt) VALUES ('" . $sexe . "','" . $username . "','" . $pseudo . "','" . $description . "','" . $description . "','" . $description . "','" . $description . "','" . $description . "','" . $description . "','" . $nb_followers . "','" . $nb_likers . "','".implode(',', $tags)."','".implode(',', $tags)."','".implode(',', $tags)."','".implode(',', $tags)."','".implode(',', $tags)."','".implode(',', $tags)."')") or die(mysqli_error($conn));
    }
    else{
           mysqli_query($conn, "UPDATE users SET bio_en='$description',bio_fr='$description',bio_es='$description',bio_it='$description',bio_de='$description',bio_pt='$description',pseudo='$pseudo',nb_likers='$nb_likers',temp_tags_en='".implode(',', $tags)."',temp_tags_fr='".implode(',', $tags)."',temp_tags_es='".implode(',', $tags)."',temp_tags_it='".implode(',', $tags)."',temp_tags_de='".implode(',', $tags)."',temp_tags_pt='".implode(',', $tags)."',is_online=1,n_last=now() WHERE username='$username' AND sexe='$sexe'") or die(mysqli_error($conn));
    }
}
mysqli_close($conn);
?> | 
Partager