I have a quick question; I want to take some information (the price) from another website and introduce it in my database to see how the price fluctuates. I am having some troubles getting the information.. I dont fully understand oop. There are 2 tries, i tried to make.. The first try, kinda dose the work i want to, but is kinda messy. I asked a friend if he knows another way, and told me about DOM, i did some research about it but i dont quite get it. If anybody knows how to expand my ideea on no2 as i have no ideea how to continue. This is just for me, to develop my skills in php and so on. Again i dont fully understand oop, so please dont be harsh on me.
Try no1
<form action="" method="POST">
<input type="radio" name="g1" value="x1">x1
<input type="radio" name="g2" value="x2">x2
<input type="radio" name="s1" value="x3">x3
<input type="radio" name="s2" value="x4">x4
<input type="submit" name="submit" value="click">
<?php
if (isset($_POST['g1'])) {
$r1 = $_POST['g1'];
name1($r1);
} elseif (isset($_POST['g2'])) {
$r2 = $_POST['g2'];
name2($r2);
} elseif (isset($_POST['s1'])) {
$r3 = $_POST['s1'];
name3($r3);
} elseif (isset($_POST['s2'])) {
$r4 = $_POST['s2'];
name4($r4);
}
?>
</form>
<?php
function name1($end) {
echo '<br>' . $end . '<br>';
$data_scrap = file_get_contents(url);
// echo $data_scrap;
$string1 = $data_scrap;
$delimiter1 = '<div class="table-cell col-xs-5 col-sm-2 col-md-3 col-lg-2">';
$dele_s = explode($delimiter1, $string1);
// echo '<br>'.$dele_s[1].'<br>';
$string2 = $dele_s[1];
$delimiter2 = '<p class="product-new-price">';
$dele_j = explode($delimiter2, $string2);
echo'<br>' . $dele_j[1] . '<br>';
// kinda works ?
}
function name2($end) {
echo $end;
//same thing here as on 1
}
function name3($end) {
echo $end;
//same thing here as on 1
}
function name4($end) {
echo $end;
//same thing here as on 1
}
?>
Try no2 How i said, i kinda have no ideea what shall i do here, but if anybody knows how to make it work, or atleast show me another way and explain it to me i will be very gratefull
<?php
$url = '';
//curl on url
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
//get content from url
$data_scrap = file_get_contents('$url');
//create DomDoc on HTML url
$dom = new DOMDocument('1.0', 'utf-8');
$element = $dom->createElement($url);
//create DOMXpath on $DomDoc
$ddom = new DOMXPath($dom);
// find price element ?
// get text ?
// analizer?
// $price (as float)