<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
date_default_timezone_set('Europe/Moscow');
require_once('config.php');
require_once('func.php');
$str = file_get_contents('https://www.сайт.ru');
//print_r($str);
$all = '/<div class="act2">([\s\S]+?)\s*<\/div>/';
preg_match_all($all, $str, $rez_all);
//print_r($rez_all['1']);
foreach ($rez_all['1'] as $val) {
$link = '/<a href="(.+?)">/';
preg_match_all($link, $val, $rez_link);
//print_r($rez_link);
echo $url = 'https://www.сайт.ru'.$rez_link['1']['0'];
$progect = file_get_contents($url);
$h1 = '/<h1>([\s\S]+?)\s*<\/h1>/';
preg_match_all($h1, $progect, $rez_h1);
print_r($rez_h1['1']);
$price = '/<b>Бюджет:<\/b>([\s\S]+?)\s*<br\/>/';
preg_match_all($price, $progect, $rez_price);
print_r($rez_price['1']);
$category = '/<b>Категория:<\/b>([\s\S]+?)\s*<br\/>/';
preg_match_all($category, $progect, $rez_category);
// print_r(end($rez_category['0']));
print_r($rez_category['1']);
$add_time = '/<br\/>Добавлено: ([\s\S]+?)\s*<br\/>/';
preg_match_all($add_time, $progect, $rez_add_time);
print_r($rez_add_time['1']['0']);
$desc = '/<table width="100%" cellpadding="5" cellspacing="1">
<tr>
<td>([\s\S]+?)\s*
<\/td>
<\/tr>
<\/table>/';
preg_match_all($desc, $progect, $rez_desc);
print_r($rez_desc['1']['0']);
$result_h1 = implode($rez_h1['1']);
$result_price = end($rez_price['1']);
$price_expl = explode(" ", $result_price);
$price_1 = $price_expl['1'];
// var_dump(mb_strlen($price_1));
if (mb_strlen($price_1) != '0') {
//print_r($price_expl);
echo $price_1 = $price_expl['1'];
var_dump(mb_strlen($price_1));
if ($price_expl['2'] === 'руб.') {
$valuta = "rubl";
}
if ($price_expl['2'] === '$') {
$valuta = "dollar";
$price_1 = $price_1 * 58;
}
if ($price_expl['2'] === 'EUR') {
$valuta = "EUR";
$price_1 = $price_1 * 61;
}
echo $valuta;
}else{
$price_1 = 0;
$valuta = "rubl";
}
$result_category = end($rez_category['1']);
$result_category_2 = category($result_category);
$result_add_time = $rez_add_time['1']['0'];
$result_desc = $rez_desc['1']['0'];
$site = "freelancejob";
print_r($result_category_2);
$time_date = date('d');
$time_mount = russian_date();
$time_year = date('Y');
$time_hour = date('H:i');
$date = date('Y-m-d H:i');
/*****************
проверка, есть ли такой заказ в базе
******************/
$stmt = $pdo->query("SELECT `id` FROM `project` WHERE link = '$url' ");
$row = $stmt->fetch();
print_r($row);
if (isset($row['id'])) {
echo "такой проект есть, пропускаю";
}else{
$stmt = $pdo->prepare("INSERT INTO `project`(`title`,`site`, `link`, `description`, `category`, `category_en`, `price`, `price_1`, `valuta`, `time_date`, `time_mount`, `time_hour`, `date`) VALUES (:title, :site, :link, :description, :category, :category_en, :price, :price_1, :valuta, :time_date, :time_mount, :time_hour, :date)");
$stmt->bindParam(':title', $result_h1);
$stmt->bindParam(':site', $site);
$stmt->bindParam(':link', $url);
$stmt->bindParam(':description', $result_desc);
$stmt->bindParam(':category', $result_category);
$stmt->bindParam(':category_en', $result_category_2);
$stmt->bindParam(':price', $result_price);
$stmt->bindParam(':price_1', $price_1);
$stmt->bindParam(':valuta', $valuta);
$stmt->bindParam(':time_date', $time_date);
$stmt->bindParam(':time_mount', $time_mount);
$stmt->bindParam(':time_hour', $time_hour);
$stmt->bindParam(':date', $date);
$stmt->execute();
}
}
?>
function test(){
$.ajax({
type: "POST",
url: "/php/set-index.php",
data: {
какие-то:параметры;
}
}).done(function( result )
{
//тут какой-нибудь код
//тут я делаю проверку, показывать push или нет
});
}
setInterval(function(){ test(''); }, 10000); //запускаю свою функцию раз в 10 секунд
//1000 - это одна секунда