loadHTML($string);
$finder = new DomXPath($dom);
$content = $finder->query("//*[contains(concat(' ', normalize-space(@data-component-name), ' '), ' ProductPage ')]")[0]->textContent;
$content = json_decode($content);
$c = $content->product;
$currency = "{
\"usd\": \"$\",
\"eur\": \"€\",
\"crc\": \"₡\",
\"gbp\": \"£\",
\"ils\": \"₪\",
\"inr\": \"₹\",
\"jpy\": \"¥\",
\"krw\": \"₩\",
\"ngn\": \"₦\",
\"php\": \"₱\",
\"pln\": \"zł\",
\"pyg\": \"₲\",
\"thb\": \"฿\",
\"uah\": \"₴\",
\"vnd\": \"₫\",
\"aud\": \"A\$\",
\"cad\": \"CAD\$\"
}";
$currency = json_decode($currency);
$currencyOutput = $c->currency_code;
if ($c->thumbnail_url == null) {
$thumbnailURL = $c->covers[0]->url;
} else $thumbnailURL = $c->thumbnail_url;
$rating = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' rating-average ')]")[0]->textContent;
if ($rating == null || $rating == "" || $rating == " ") $rating = "None";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
$failed = true;
}
$c->name = str_replace("'","\'",str_replace("`","\`",str_replace('"','\"',$c->name)));
$c->seller->name = str_replace("'","\'",str_replace("`","\`",str_replace('"','\"',$c->seller->name)));
$species = str_replace("'","\'",str_replace("`","\`",str_replace('"','\"',$species)));
$sql2 = "SELECT * FROM `content` WHERE
name LIKE \"%" . $c->name . "%\" AND
url_link LIKE \"%" . $url . "%\" AND
url_image LIKE \"%" . $thumbnailURL . "%\" AND
creator LIKE \"%" . $c->seller->name . "%\";";
$result2 = $conn->query($sql2);
if ($result2->num_rows > 0) {
$isExisting = true;
} else {
$isExisting = false;
}
$sql = "INSERT INTO content (
`name`,
`price`,
`currency`,
`url_link`,
`url_image`,
`creator`,
`rating`,
`species`,
`nsfw`,
`section`
)
VALUES (
'" . $c->name . "',
'" . $c->price_cents . "',
'" . $currency->$currencyOutput . "',
'" . $url . "',
'" . $thumbnailURL . "',
'" . $c->seller->name . "',
'" . $rating . "',
'" . $species . "',
'" . $nsfw . "',
" . $section . "
)";
if ($isExisting == false) {
if ($conn->query($sql) === TRUE) {
echo "Successful !";
} else {
$errormsg = "Error: " . $sql . "
" . $conn->error . "";
$failed = true;
}
} else {
echo "Already Exists!";
}
$conn->close();
}
?>